如何使用window.location.replace javascript?
发布时间:2020-12-13 20:25:27 所属栏目:Windows 来源:网络整理
导读:我的网址 http://www.mysite.com/folder1/page1.aspxhttp://www.mysite.com/folder1/page1.aspx?id=1http://www.mysite.com/folder1/page1.aspx?id=1dt=20111128 重定向页面 http://www.mysite.com/folder1/page2.aspx 我想从page1.aspx重定向到page2.aspx
我的网址
http://www.mysite.com/folder1/page1.aspx http://www.mysite.com/folder1/page1.aspx?id=1 http://www.mysite.com/folder1/page1.aspx?id=1&dt=20111128 重定向页面 http://www.mysite.com/folder1/page2.aspx 我想从page1.aspx重定向到page2.aspx 如何在page1.aspx中写一个javascript? window.location.replace("/page2.aspx"); window.location.replace("../page2.aspx"); window.location.replace("~/page2.aspx"); 第一个2给了我这个. http://www.mysite.com/page2.aspx 最后一次给了我这个. http://www.mysite.com/folder1/~/page2.aspx 什么是正确的使用方法?
包括没有路径信息,就像在链接中:
window.location.replace("page2.aspx"); Here’s a live example这个例子在之间切换 http://jsbin.com/asupup/2 -- The "2" corresponds to your "page1.aspx" …和 http://jsbin.com/asupup/3 -- The "3" corresponds to your "page2.aspx" …所以2页使用 window.location.replace("3"); …和3页使用 window.location.replace("2"); 有关URL(特别是相对URL)如何工作的更多信息,请参阅RFC3986.但是基本上: >如果相对URL不以.或/,它替代最后一个细分.所以: http://foo.com/one/two/page.html + bar.html = http://foo.com/one/two/bar.html >如果相对URL以../开头,它将替换最后一个片段和上一个片段. http://foo.com/one/two/page.html + ../bar.html = http://foo.com/one/bar.html 请注意,这两个子文件夹已被替换.多个../s可以用来上移多个级别: http://foo.com/one/two/three/four/page.html + ../../bar.html = http://foo.com/one/two/bar.html >如果相对URL以单个/开头,则会替换主机名(和端口(如果有))后面的所有内容.所以: http://foo.com/one/two/page.html + /bar.html = http://foo.com/bar.html http://foo.com:8080/one/two/page.html + /bar.html = http://foo.com:8080/bar.html >如果一个相对URL以//开头,它将替换协议之后的所有内容,因此: http://ex.com/folder/page.html + //foo.com = http://foo.com (这在加载资源时很方便,并且您想避免担心http与https和混合内容警告.) (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- 在WP7上格式化XAML中的日期
- windows – 为什么ReadDirectoryChangesW省略事件?
- windows-phone-7 – WP8 – 此软件包使用的应用程序名称尚未
- windows – 希望通过命令行将“作为服务登录”权限添加到帐
- 使用Windows API在c中异步操作:使用哪种方法以及为什么我的
- windows – 具有内部存储的双节点故障转移群集
- windows – Splunk的替代品?
- windows – 使用java web start实现自动更新桌面应用程序时
- Windows nvm的安装使用(及排坑)
- windows-server-2008 – 在Windows Server上使用内置软件-R
推荐文章
站长推荐
- windows-installer – windows Installer – 当安
- 如何在Windows Phone 8中打开pdf文件?
- windows-xp – 在Windows XP中自动安装软件
- Windows XP x86检查构建?
- R和RStudio找不到Rprofile.site
- powershell – windows docker图像是否与windows
- 在Windows Installer Commit中运行批处理文件
- windows-phone-7 – WP7 Live Tile文字颜色?
- windows下的WAMP环境搭建图文教程(推荐)
- 批处理文件 – 将文本发送到Windows控制台应用程
热点阅读