js中top.location.href、parent.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页面跳转

--------------------- 本文来自 z18842589113 的CSDN 博客 ,全文地址请点击:https://blog.csdn.net/z18842589113/article/details/53316287?utm_source=copy 

原文地址:https://www.cnblogs.com/asdyzh/p/9742536.html