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"

更多相关文章

  1. java 如何获取动态网页内容,返回字符串
  2. 原创记忆小游戏-HTML网页版
  3. javascript实现查看html网页放大图片功能
  4. How to learn js properly(week4)使用js建立的动态测试网页
  5. 使用HTML或Javascript替换网页上的文本
  6. 小弟初学网页(javascript),看不懂下面的代码。但又要完成任务 各位
  7. javascript小实例,PC网页里的拖拽
  8. 使用一个CSS选择网页外观而无需重新加载
  9. Python网页静态爬虫

随机推荐

  1. AndroidStudio安装及配置Gradle遇到的Err
  2. android xutils
  3. android ctl属性的实现过程
  4. Android 应用程序构成
  5. android在处理一写图片资源的时候,会进行
  6. android sim卡 TelephonyManager类:Androi
  7. 【自学Android】使用ModelView,DataBindi
  8. Android动画学习笔记-Android Animation
  9. android 开启Https单向认证
  10. textview设置文本每行的行间距