首页 > Windows开发 > 详细

window.location.href和window.location.replace的区别

时间:2015-10-21 17:27:42      阅读:198      评论:0      收藏:0      [点我收藏+]
有3个html页面(1.html, 2.html, 3.html)。

进系统默认的是1.html ,当我进入2.html的时候, 
2.html里面用window.location.replace("3.html");与用window.location.href("3.html");
从用户界面来看是没有什么区别的, 但是当3.html页面有一个“返回”按钮,调用window.history.go(
-1);wondow.history.back();
方法的时候,一点这个返回按钮就要返回2.html页面的话,区别就出来了, 当用window.location.replace(
"3.html");连到3.html页面的话, 3.html页面中的调用window.history.go(-1);wondow.history.back();方法是不好用的,会返回到1.html 。 当用window.location.href("3.html");连到3.html页面的话, 3.html页面中的调用window.history.go(-1);wondow.history.back();方法是好用的,会返回2.html。 因为window.location.replace("3.html");是不向服务器发送请求的跳转, 而window.history.go(-1);wondow.history.back();方法是根据服务器记录的请求决定该跳到哪个页面的, 所以会跳到系统默认页面1.html 。window.location.href("3.html");是向服务器发送请求的跳转,window.history.go(-1);wondow.history.back();方法是根据服务器记录的请求决定该跳到哪个页面的, 所以就可以返回到2.html。

 

window.location.href和window.location.replace的区别

原文:http://www.cnblogs.com/qhorse/p/4898268.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!