欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

js控制页面跳转

程序员文章站 2022-04-18 11:53:51
...
[size=xx-large][color=orange][b]js控制页面跳转[/b][/color][/size]

 1 window.open("http://www.xxx.com", "_self")
此方法的作用是控制济览器打开窗口,加上"_self"属性时在自身窗口打开。


2 location对像是window对像的一个子对像,可以使用如下方法:
window.location = "http://www.xxx.com";
window.location.href = "http://www.xxx.com";
这两种方法和
location = "http://www.xxx.com";
location.href = "http://www.xxx.com";
是等价的。这几种方式在各个浏览器下支持较好,且执行后后面的代码仍然会起作用。


location还有一个replace()方法,作用是导航到指定页面,并且屏蔽“后退”按钮。这个方法

在安全级别较高的场合如银行系统中比较有用,但它在VISTA+IE7下无法屏蔽“后退”按钮,可能

是因为VISTA安全设置的问题,禁止了脚本对浏览器的操作。


window.top.location = "http://www.xxx.com";
top.location.href = "http://www.xxx.com";
这两种写法等价,一般应用在框架中,作用是在母框架打开,即将整个页面替换掉。


3 window.history.go(-1);/window.history.back();
window.history.go(1);/window.history.forward();
前两个方法作用相当于“后退”按钮,后两个方法相当于“前进”按钮。这些方法在VISTA下同样会有问题。


4 document.URL = "http://www.xxx.com")
此方法设置了页面的URL后,后面的代码依然会执行,但它在在FireFox下不通用,建议一般使用location的相关方法



1、window.open之后,子页面关闭之前刷新子页面,目前测试过的刷新方法:
1.1 window.opener.location.reload(); 该方式使用时会提示你是否确定刷新,比较烦人。
1.2 window.opener.location.href=window.opener.location.href; 该方式不会弹窗;

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(location)
8 document.URL=location.href



转自:[url]http://blog.csdn.net/lolinzhang/article/details/3952128[/url]