如何将window.location设置为特定路径(没有主机)? [英] How do I set window.location to a specific path (without a host)?
本文介绍了如何将window.location设置为特定路径(没有主机)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用窗口定位方法在一段时间后将网页重定向到另一个网页。
I am using the window location method to redirect a webpage to another after a set amount of time.
网址需要从www.myurl.com/home更改为www.myurl.com/other。问题是我不知道最终的URL是什么,所以我不能使用绝对链接,它们必须只是一个路径。这是我到目前为止:
The url needs to change from www.myurl.com/home to www.myurl.com/other. The problem is that I do not know what the final URLs will be so I cannot use absolute links, they have to be a path only. This is what I have so far:
window.location.pathname = "mobility.html"
推荐答案
你可以只加一个 /
到您的URL以使它们相对于域根目录(无需对域名进行硬编码)。像这样:
You can just prepend a /
to your URL to make them relative to the domain root (without having to hardcode the domain name). Like this:
window.location = "/mobility.html"
这篇关于如何将window.location设置为特定路径(没有主机)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文