如何将window.location设置为特定路径(没有主机)?
16lz
2021-01-22
I am using the window location method to redirect a webpage to another after a set amount of time.
我使用窗口定位方法在一段时间后将网页重定向到另一个网页。
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:
该网址需要从www.myurl.com/home更改为www.myurl.com/other。问题是我不知道最终的URL是什么,所以我不能使用绝对链接,它们必须只是一个路径。这是我到目前为止:
window.location.pathname = "mobility.html"
2 个解决方案
#1
25
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:
您可以在URL之前添加/,使它们相对于域根目录(无需对域名进行硬编码)。喜欢这个:
window.location = "/mobility.html"
更多相关文章
- java 如何获取动态网页内容,返回字符串
- 原创记忆小游戏-HTML网页版
- javascript实现查看html网页放大图片功能
- How to learn js properly(week4)使用js建立的动态测试网页
- 使用HTML或Javascript替换网页上的文本
- 小弟初学网页(javascript),看不懂下面的代码。但又要完成任务 各位
- javascript小实例,PC网页里的拖拽
- 使用一个CSS选择网页外观而无需重新加载
- Python网页静态爬虫