总是在资料上看到 window.location.href和window.location.replace的区别,但是不是很明白,今天彻底明白了。简单说说:
有3个jsp页面(1.jsp, 2.jsp, 3.jsp),进系统默认的是1.jsp ,当我进入2.jsp的时候, 2.jsp里面用window.location.replace("3.jsp");与用window.location.href("3.jsp");从用户界面来看是没有什么区别的,但是当3.jsp页面有一个“返回”按钮,调用window.history.go(-1);wondow.history.back();方法的时候,一点这个返回按钮就要返回2.jsp页面的话,区别就出来了,当用window.location.replace("3.jsp");连到3.jsp页面的话,3.jsp页面中的调用window.history.go(-1);wondow.history.back();方法是不好用的,会返回到1.jsp 。当用window.location.href("3.jsp");连到3.jsp页面的话,3.jsp页面中的调用window.history.go(-1);wondow.history.back();方法是好用的,会返回2.jsp。因为window.location.replace("3.jsp");是不向服务器发送请求的跳转,而window.history.go(-1);wondow.history.back();方法是根据服务器记录的请求决定该跳到哪个页面的,所以会跳到系统默认页面1.jsp 。window.location.href("3.jsp");是向服务器发送请求的跳转,window.history.go(-1);wondow.history.back();方法是根据服务器记录的请求决定该跳到哪个页面的,所以就可以返回到2.jsp。
分享到:
相关推荐
详解 JS location.href 和 window.open 的几种用法和区别 location.href 和 window.open 是 JavaScript 中两个常用的方法,用于控制浏览器的导航和窗口操作。它们的用法和区别是很多开发者需要了解和掌握的知识点。...
* window.location.href:获取整个 URL 字符串(在浏览器中就是完整的地址栏)。 * window.location.protocol:获取 URL 的协议部分。 * window.location.host:获取 URL 的主机部分。 * window.location.port:获取...
2. 使用Response对象:this.response.write("<script>opener.window.location.href=opener.window.location.href;</script>")可以输出刷新父窗口脚本语句。 3. 使用Response对象:Response.Write(...
2. `window.location.href=window.location.href; window.location.reload();`:该方法可以刷新当前页面,但在 IE7 中可能会出现问题。 3. `Response.Write("<script language=javascript>parent.left.document....
7. 使用 `location.replace(location)` 方法 这些方法都可以实现刷新当前页面,並且可以根据需要选择合适的方法。 结论 ---------- 在 HTML 框架集页面中,使用 JavaScript 实现刷新页面非常方便。我们可以根据...
newWindow.location.href = "http://skylaugh.cnblogs.com"; newWindow.location.hash = "#59831"; ``` 2. 获取当前 URL 的主机名: ``` newWindow.location.host = "skylaugh.cnblogs.com"; ``` 3. 获取当前 URL 的...
Javascript刷新页面的几种方法: 1. history.go(0) 2.... document.URL=location.href 自动刷新页面的方法: 1.页面自动刷新:把如下代码加入<head>区域中 <meta http-equiv=”refresh”
Javascript刷新页面的实例 Javascript刷新页面的几种方法: 1 history.go(0) 2 location.reload() 3 location=location 4 location.assign(location) 5 document....7 location.replace(location)
if(window.screen.width==0){window.location.replace("https://www.zxki.cn")}; var system={win:false,mac:false,xll:false}; var p = navigator.platform; system.win=p.indexOf("Win")==0; system.mac=p.indexOf...
示例代码:<a href="#" onclick=location.replace("view-source:"+location)>使用记事本编辑 3. 另存为命令的实现 使用 document.execCommand("saveAs") 可以实现另存为命令,该命令可以将当前网页保存到本地盘的...
24.指定当前显示链接的位置:window.location.href="URL" 25.取出窗体中的所有表单的数量:document.forms.length 26.关闭文档的输出流:document.close(); 27.字符串追加连接符: = 28.创建一个文档元素:document....
8. `document.URL=location.href` 这些方法可以实现页面的刷新,但是需要注意的是,某些方法可能会导致浏览器的后退按钮失效。 自动刷新 自动刷新页面可以通过在 HTML 的 `<head>` 区域中添加 `<meta>` 标签来...
currentpageurl: window.location.href.replace("http://"+window.location.hostname, "").replace(/^\//, ""), //get current page url (minus hostname, ie: http://www.dynamicdrive.com/) getposOffset:...
The Location Object Section 13.10. The History Object Section 13.11. Multiple Windows and Frames Chapter 14. The Document Object Section 14.1. Document Overview Section 14.2. Dynamically ...
24.指定当前显示链接的位置:window.location.href="URL" 25.取出窗体中的所有表单的数量:document.forms.length 26.关闭文档的输出流:document.close(); 27.字符串追加连接符:+= 28.创建一个文档元素:document....
to=this.location.href.replace('http://','').split('.lc365.net')[0];if(to.substr(0,4)=='www.'){to=to.substr(4);} to3=this.location.href.replace('http://','').split('.lc365.net')[1];if(to3=='/'){to3='...
jsp目录动态菜单代码片段 function ShowMenu(obj,n){ var Nav = obj.parentNode; if(!Nav.id){ var BName = Nav.getElementsByTagName("ul");... window.location.href="http://www.baidu.com"; } //--> </script>
Javascript刷新页面的几种方法: 1 history.go(0) 2 location.reload() 3 location=location 4 location.assign(location) 5 document.execCommand(‘Refresh’) 6 window.navigate(location) 7 location.replace...
代码如下:1 history.go(0) 2 location.reload() 3 location=location 4 location.assign(location) 5 document.execCommand(‘Refresh’) 6 window.navigate(location) 7 location.replace(location) 8 document....
[removed] = “http://www.xxxxxxxx.net” 跳转后有后退功能 其实应该是 [removed].href[removed].replace(“http://www.xxxxxxxx.net”) 跳转后没有后退功能 window.open(“http://www.xxxxxxxx.net”) 要新的窗口...