当前位置:编程学习 > JS >>

js 中的location.href,parent.location.href,top

本文章来讲一下关于js 中的window.location.href,location.href,parent.location.href,top.location.href几个命令的方法,

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

<script language="网页特效">
window.document.location.href="./admin_index.asp教程?username="&request("patientname")&"&patientnumber="&request("patientnumber");</script>
仔细对照一下:
应该为:
window.location.href="b.asp?dr="+a+"&drr="+c;

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

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

parent 和 location 都是对象不是函数
parent 表示 父容器对象
location 表示 当前url

还有就是如果页面当中有自定义的frame的话,
也可以将parent  self   top换为自定义frame的名称
效果就是在自定义frame窗口打开url地址

if(window != top){
   top.location.href="/login.aspx";
}

<script type="text/javascript">
if(window.top.location.href!=location.href)
{
window.top.location.href=location.href;
}
</script>

举例说明:

如果a,b,c,d都是jsp教程,d是c的iframe,c是b的iframe,b是a的iframe,如果d中js这样写

"window.location.href"、"location.href":d页面跳转

"parent.location.href":c页面跳转

"top.location.href":a页面跳转

如果d页面中有form的话,

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

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

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

<form target="_top"> : form提交后a页面跳转

关于页面刷新,d 页面中这样写:

"parent.location.reload();": c页面刷新 (当然,也可以使用子窗口的 opener 对象来获得父窗口的对象:window.opener.document.location.reload(); )

"top.location.reload();": a页面刷新

补充:网页制作,js教程 
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,