window.location.replace 和 window.location.href 的区别
来源:互联网 发布:交银数据混合519698 编辑:程序博客网 时间:2024/05/16 10:24
昨天在处理一个具有返回功能的按钮时花了一些时间,就是返回到用户搜索的前一页,我用的是 window.location.go(-1)
,这就是正正经经的浏览器返回到前一条浏览记录的做法。可是有几个返回按钮却一直失灵,点击之后,可以看到浏览器刷新,但是还是停留在原来的页面。
仔细查看代码,终于发现了原因。就是用户从上一个页面 a 跳转到目前看到的这一个页面 c,其实中间还有一个页面 b,只是用户看不到,因为从 a 跳转到 b 后,执行 b 的脚本,b 的脚本有下面这句:
window.location.href = "c.html";
所以页面嗖的一下就跳到了 c 页面,但是浏览器记录却记录了三个页面:a, b, c.
这个时候点击返回按钮从 c 就是返回到 b,而 b 又会马上跳转到 c,所以就出现了点击返回按钮,页面刷新后,还是停留在原来页面的情况。
解决方案就是把上面重定位的脚本换成下面这句:
window.location.replace("c.html");
window.location.replace(url) replaces the current location in the address bar by a new one. The page that was calling the function, won’t be included in the browser history. Therefore, on the new location, clicking the back button in your browser would make you go back to the page you were viewing before you visited the document containing the redirecting JavaScript.
window.location.replace(url)
将目前浏览器的地址替换掉,调用这个方法的网页,将不会被写入浏览记录。所以,网页 b 不会被写入浏览记录,从网页 a 经过 b 跳转到 c,再点击返回按钮将跳转到 a.
- window.location.href和window.location.replace的区别
- window.location.href和window.location.replace的区别
- window.location.href和window.location.replace的区别
- window.location.href和window.location.replace的区别
- window.location.href和window.location.replace的区别
- window.location.href和window.location.replace的区别
- window.location.href和window.location.replace的区别
- window.location.href和window.location.replace的区别
- window.location.href和window.location.replace的区别
- window.location.href和window.location.replace的区别
- window.location.href和window.location.replace的区别
- window.location.href和window.location.replace的区别
- window.location.href和window.location.replace的区别
- window.location.href和window.location.replace的区别
- window.location.href和window.location.replace的区别
- window.location.href和window.location.replace的区别
- window.location.href和window.location.replace的区别
- window.location.replace 和 window.location.href 的区别
- 拆分系统拆分盘盛出不穷,互助系统的延续走出新的路子,农场果园直销系统返利系统开始火了!
- OpenCV3.0机器学习算法使用
- python 将 csv(中文) 导入mysql 数据库的简单代码
- 微信硬件蓝牙开发之唯一二维码和型号二维码区别(14)
- D
- window.location.replace 和 window.location.href 的区别
- Android 微信支付和支付宝支付 快速接入
- jq上传多张图片(带进度条)
- 关于C语言中加法的实现原理
- 共阴极数码管60秒表显示
- 基于android的远程视频监控系统(已开放源码)
- Art和Dalvik对比以及虚拟机的原理
- malloc和free函数 简介
- dubbo注解暴露服务与接收服务