js中有哪些方式可以实现页面的跳转

JavaScript07

js中有哪些方式可以实现页面的跳转,第1张

1、改变当前页面的url实现跳转:例如

window.location="http://zhidao.baidu.com"

2、在当前窗口打开新页面也可以实现页面跳转:

window.open("http://zhidao.baidu.com",'_self')

javascript中的location.href有很多种用法,主要如下:

self.location.href="/url" 当前页面打开URL页面

location.href="/url" 当前页面打开URL页面

windows.location.href="/url" 当前页面打开URL页面,前面三个用法相同

this.location.href="/url" 当前页面打开URL页面

parent.location.href="/url" 在父页面打开新页面

top.location.href="/url" 在顶层页面打开新页面

添加以下代码执行就可以了

<SCRIPT

LANGUAGE="JavaScript">

<!-

var

anchors

=

document.getElementById("DIV名").getElementsByTagName("a")

for(var

i=0i<anchors.lengthi++)

{var

anchor

=

anchors[i]anchor.target="_blank"}

//–>

</SCRIPT>

注解:target="_blank"

这个代码就是新窗口打开效果。