admin管理员组文章数量:1418636
Let's say I have a page located here in my website:
mywebiste/section1/slideshow/main/example.html
I'd like to use window.open()
to access these pages in my website:
mywebsite/section2/index.html
mywebsite/section2/article1/gallery.html
mywebsite/login.php
These are just random examples, but I'm trying to point out that they are very far away from the example.html
page, and I would have to use a lot of ../
and as such ending up with very long (and confusing) URLs.
I thought that there should be a way to directly access the root of the website, but still using relative URLs. (Like if a shortcut .../
or root/
existed and that could redirect you to the root).
Is this possible?
Let's say I have a page located here in my website:
mywebiste./section1/slideshow/main/example.html
I'd like to use window.open()
to access these pages in my website:
mywebsite./section2/index.html
mywebsite./section2/article1/gallery.html
mywebsite./login.php
These are just random examples, but I'm trying to point out that they are very far away from the example.html
page, and I would have to use a lot of ../
and as such ending up with very long (and confusing) URLs.
I thought that there should be a way to directly access the root of the website, but still using relative URLs. (Like if a shortcut .../
or root/
existed and that could redirect you to the root).
Is this possible?
Share Improve this question asked Mar 22, 2016 at 13:08 YonicYonic 3173 silver badges15 bronze badges2 Answers
Reset to default 5Just to preface with a /
should work.
window.open('/section2/index.html', ...); // etc
You can use window.location.origin
in JavaScript which returns the protocol, hostname and port.
For instance:
window.open(window.location.origin + '/other-folder/index.html');
This is not IE patible, but you can try this polyfill: http://tosbourn./a-fix-for-window-location-origin-in-internet-explorer/
本文标签: javascriptHow to quickaccess the root of my website using windowopen()Stack Overflow
版权声明:本文标题:javascript - How to quick-access the root of my website using window.open()? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745296116a2652089.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论