| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2417 人关注过本帖
标题:window.location="";和location.replace("");有什么区别? ...
只看楼主 加入收藏
海风308
Rank: 1
等 级:新手上路
帖 子:64
专家分:0
注 册:2008-10-28
结帖率:100%
收藏
 问题点数:0 回复次数:4 
window.location="";和location.replace("");有什么区别?
请问:
window.location="";和location.replace("");有什么区别?
这两个都能让网页导向令一个网址,那么有什么区别呢?比如能带参数,不能带参数之类的.
搜索更多相关主题的帖子: location 
2008-12-11 13:53
徐强
Rank: 2
等 级:新手上路
威 望:3
帖 子:72
专家分:0
注 册:2007-3-30
收藏
得分:0 
Replace?还是Reload()?
好像没什么区别吧?没试过
2008-12-11 14:40
海风308
Rank: 1
等 级:新手上路
帖 子:64
专家分:0
注 册:2008-10-28
收藏
得分:0 
是replace(),reload()是重新加载本页,而replace()可以导向另外一个URL
2008-12-11 14:50
bygg
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:乖乖的心中
等 级:版主
威 望:241
帖 子:13555
专家分:3076
注 册:2006-10-23
收藏
得分:0 
给你举个例子:
我们现在有3个页面(a.html, b.html, c.html).
默认打开a.html页面,然后在a.html页面中通过一个链接转向a.html页面。
现在,我在b.html页面中用window.location.replace("c.html");与用window.location.href("c.html");分别进入c.html页面.
从用户界面来看是没有什么区别的,但是现在c.html页面有一个“返回”按钮,
用window.location.href("c.html");进入c.html页面时,
    c.html页面中的调用window.history.go(-1);wondow.history.back();进入c.html页面时,一点这个"返回"按钮就要返回b.html页面的话,
而如果用window.location.replace("c.html");进入c.html页面的话,
    c.html页面中的调用window.history.go(-1);wondow.history.back();方法是不好用的,会返回到a.html.

因为window.location.replace("c.html");是不会向服务器发送请求而进行跳转,而window.history.go(-1);wondow.history.back();方法是根据服务器记录的请求决定该跳到哪个页面的,所以会跳到系统默认页面a.html 。
window.location.href("c.html");是向服务器发送请求的跳转,window.history.go(-1);wondow.history.back();方法是根据服务器记录的请求决定该跳到哪个页面的,所以就可以返回到b.html。

飘过~~
2008-12-11 15:41
海风308
Rank: 1
等 级:新手上路
帖 子:64
专家分:0
注 册:2008-10-28
收藏
得分:0 
谢谢版主认真回答!
2008-12-11 17:58
快速回复:window.location="";和location.replace("");有什么区别? ...
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.017325 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved