龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > web编程 > Javascript编程 >

js中top.location.href、parent.location.href用法

时间:2012-12-29 08:41来源:未知 作者:admin 点击:
分享到:
在很多朋友不清楚在js中window.location.href、location.href、parent.location.href、top.location.href他们的用法,下面我来分别介绍。 window.location.href、location.href是本页面跳转 parent.location.href是上一层
在很多朋友不清楚在js中window.location.href、location.href、parent.location.href、top.location.href他们的用法,下面我来分别介绍。

window.location.href、location.href是本页面跳转

parent.location.href是上一层页面跳转

top.location.href是最外层的页面跳转

举例说明:

window.location.href、location.href:

例:

 代码如下

window.location.href= 'wapsend1.asp?zimu=A&rev= '   +   form1.rev.value ;

parent.location.href:C页面跳转

例:

 代码如下

window.parent.parent.location.href=“你定义要跳转的页面”

top.location.href:A页面跳转

例:

在form提交表单的时候有个属性可能对上面的(2)的情况有用target=_top

 代码如下

<form name=loginForm action=Login.action method=post target=_top>

</form>

例2

 代码如下

echo <iframe width=0 height=0 frameborder=0 scrolling=auto src='登录论坛' onload='reurl()'></iframe>;
echo <script> function reurl(){top.location.href='.$url.'}</script>;

也可以直接在表单提交是的target加个即可

<form>: form提交后D页面跳转

<form target=_blank>: form提交后弹出新页面

<form target=_parent>: form提交后C页面跳转


精彩图集

赞助商链接