Jquery基础(七) window.parent与window.openner区别
来源:互联网 发布:php充值提现网站源码 编辑:程序博客网 时间:2024/05/21 04:16
一、今天总结一下js中几个对象的区别和用法:
1."window.location.href"、"location.href"是本页面跳转
2."window.parent.location.href"是上一层页面跳转
3."window.top.location.href"是最外层的页面跳转
二、举例说明:
如果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页面跳转
现在终于明白了连接的时候target的用法了:
_blank:重新打开一个窗口
_parent:父窗口执行重定向
_self:自身页面重定向
_top:第一个父窗口重定向
小结:
1.window.open("Url地址","_blank") = window.open("Url地址");//在新窗口打开 2.location = window.location = location.href = window.location.href =self.location.href = "Url地址";//在D页面实现展现 window.open("Url地址","_self");//在D页面实现展现3.parent.location.href = window.parent.location.href ="Url地址";//在C页面实现展现 window.open("Url地址","_parent");//在C页面实现展现4.top.location.href = window.top.location.href ="Url地址";//在A页面实现展现 window.open("Url地址","_top")//在A页面实现展现5.parent.parent.location = "Url地址";//在B页面实现展现 parent.open("Url地址","_parent") = parent.parent.open("Url地址","_self")//在B页面实现展现
综上所述可知:parent.window:父窗口对象 top.window:第一个父窗口的对象
三、重点看看window.parent与window.openner区别
window.parent 是iframe页面调用父页面对象,当我们想从iframe内嵌的页面中访问外层页面是可以直接利用window.parent获取;
例子如下:A.html<html><head> <title>父页面</title></head><body> <form id="form1" action=""> <div> 输入值: <input type="text" name="username" id="username" /><br /> <iframe src="b.html" width="400px" height="300px"></iframe> </div> </form></body></html>B.html<html><head><script type="text/javascript"> function getpValue() { document.getElementByIdx_x_x_x("span1").innerText=window.parent.document.getElementByIdx_x_x_x("username").value; }</script></head><body><span>文本框值为:</span><span id="span1"></span><br /><input type="button" value="获取父窗口内的文本框值" onclick="getpValue();"></body></html>
例子如下
a.html<html><head> <title>父页面</title> <script type="text/javascript"> function openB() { window.open('b.html','b','width=400,height=200,status=no,toolbar=no,menubar=no,location=no,resizable=yes,left=200,top=100'); } </script></head><body> <form id="form1" action=""> <div> 输入值: <input type="text" name="username" id="username" /><br /> <input type="button" value="打开窗口B" onclick="openB();" /><br /> <a href="b.html" target="_blank">超链接打开B页面</a> </div> </form></body></html>b.html<html><head><script type="text/javascript"> function getpValue() { document.getElementByIdx_x_x_x("span1").innerText=window.opener.document.getElementByIdx_x_x_x("username").value; }</script></head><body><span>文本框值为:</span><span id="span1"></span><br /><input type="button" value="获取父窗口内的文本框值" onclick="getpValue();"></body></html>
四、下面来举几个常用的例子:
parent.window与top.window一般在分割的页面即 frameset或iframe中使用
注销整个框架后返回到login.aspx:parent.window.location='Login.aspx'或者 top.window.location='Login.aspx'
window.parent也是常在框架中使用,
刷新:window.parent.location.reload();或者刷新某个框架:window.parent.MainForm.location.reload();
获得其他框架的元素值:window.parent.MainForm.form1.text1.value;
window.opener主要是获得通过超链接或者 window.open() 打开本身页面的页面的一些,比如获得值,刷新等
刷新:window.opener.location.reload();
获值:window.opener.document.getElement("txtName").value;
后退:top.playFrame.history.go(-1);
前进: top.playFrame.history.go(1);
刷新: top.playFrame.location.reload();
- Jquery基础(七) window.parent与window.openner区别
- window.parent与window.openner区别
- window.parent与window.openner区别
- window.parent与window.openner区别介绍
- window.parent与window.openner区别介绍
- window.parent与window.openner区别介绍
- window.parent与window.openner区别
- window.parent与window.openner区别介绍
- window.parent与window.openner区别 (转载)+原创
- window.self ,window.parent ,window.openner的使用
- window.parent与window.opener的区别
- window.opener 与 window.parent 的区别
- window.opener 与 window.parent 的区别
- window.opener 与 window.parent 的区别
- window.parent与window.opener的区别
- window.parent与window.opener的区别
- window.parent与window.opener的区别
- window.parent与window.opener的区别
- 一款简单易用的 Toast 组件,支持 Android&iOS
- python 脚本IndexError: tuple index out of range
- Android Studio 常用快捷键大全
- ROS讲座 关于ROS2和Gazebo C++ in Open Source Robotics
- 网页搜取和部分截取,基于Heritrix
- Jquery基础(七) window.parent与window.openner区别
- 设计模式<一>-单例模式
- Struts2入门-Hello Word实例
- xcode 7.3.1 提示没有智能提示解决办法
- Android常用第三方支付
- iOS解决Cookie登录问题(记住第三方的cookie,下次登录记住cookie并设置cookie)
- momentum动量方法
- linux中svn的搭建
- eclipse如何调试system_server