js中top、self、parent
1.在应用iframe或者frameset的时候
parent指的是父窗口。top指的是顶级的窗口。self指的是当前的窗口-window
window.self
功能:是对当前窗口自身的引用。它和window属性是等价的。
语法:window.self
注:window、self、window.self是等价的。
window.top
功能:返回顶层窗口,即浏览器窗口。
语法:window.top
注:如果窗口本身就是顶层窗口,top属性返回的是对自身的引用。
window.parent
功能:返回父窗口。
语法:window.parent
注:如果窗口本身是顶层窗口,parent属性返回的是对自身的引用。
在框架网页中,一般父窗口就是顶层窗口,但如果框架中还有框架,父窗口和顶层窗口就不一定相同了。
判断当前窗口是否在一个框架中:
<script type="text/javascript">
var b = window.top!=window.self;
document.write( "当前窗口是否在一个框架中:"+b );
</script>
你应当将框架视为窗口中的不同区域,框架是浏览器窗口中特定的部分。一个浏览器窗口可以根据你的需要分成任意多的框架,一个单个的框架也可以分成其它多个框架,即所谓的嵌套框架。
2.在同一个页面中,使用js获取另一个iframe中的dom元素
parent.html
<iframe id="myframe" name="myframe" src="http://localhost:888/child.html" frameborder="3" style="width:300;height:200;">
</iframe>
<iframe id="myframe0" src="http://localhost:888/child0.html" frameborder="3" style="width:300;height:200;" name="if2">
</iframe>
<script>
function init() {
var obj1 = document.getElementById("myframe");
console.log(obj1.src);
//alert(obj1.window.document.myform.username.value);//错误
var obj2 = document.frames("myframe"); //获取报错
console.log(obj2.window.document.myform.username.value);
//alert(obj2.src);//错误
}
init()
</script>
child0.html
child0
<div id="child0">123</div>
child.html
<form name="myform">
用户名:
<input type="text" name="username" value="test" />
</form>
<script>
console.log(parent.frames['if2'].document.getElementById("child0"))
var b = window.top != window.self;
document.write("当前窗口是否在一个框架中:" + b);
</script>
js中top、self、parent的更多相关文章
- js中 opener和parent的差别
opener即谁打开我的,比方A页面利用window.open弹出了B页面窗体.那么A页面所在窗体就是B页面的opener.在B页面通过opener对象能够訪问A页面. parent表示父窗体,比方一 ...
- 【转】Js中的window.parent ,window.top,window.self 详解
[转自]http://blog.csdn.net/zdwzzu2006/article/details/6047632 在应用有frameset或者iframe的页面时,parent是父窗口,top是 ...
- Js中的window.parent ,window.top,window.self 详解
在应用有frameset或者iframe的页面时,parent是父窗口,top是最顶级父窗口(有的窗口中套了好几层frameset或者iframe),self是当前窗口, opener是用open方法 ...
- Js中的window.parent ,window.top,window.self ,window.openner详解
在应用有frameset或者iframe的页面时,parent是父窗口,top是最顶级父窗口(有的窗口中套了好几层frameset或者iframe),self是当前窗口, opener是用open方法 ...
- Js中的window.parent ,window.top,window.self详解
在应用有frameset或者iframe的页面时,parent是父窗口,top是最顶级父窗口(有的窗口中套了好几层frameset或者iframe),self是当前窗口, opener是用open方法 ...
- Js中的window.parent ,window.top,window.self 了解
在应用有frameset或者iframe的页面时,parent是父窗口,top是最顶级父窗口(有的窗口中套了好几层frameset或者iframe),self是当前窗口, opener是用open方法 ...
- js中top.location.href、parent.location.href用法
window.location.href.location.href是本页面跳转 parent.location.href是上一层页面跳转 top.location.href是最外层的页面跳转 举例说 ...
- js中top、clientTop、scrollTop、offsetTop的区别 文字详细说明版【转】
之前在修改IE6下的一个显示bug时,查到过这些,贴这备忘,后面给出了详细说明,以前的版本,没仔细的说明,特希望大家也收藏下. 网页可见区域宽: document.body.clientWidth ...
- js中top、clientTop、scrollTop、offsetTop的区别 文字详细说明版
网页可见区域宽: document.body.clientWidth;网页可见区域高: document.body.clientHeight;网页可见区域宽: document.body.offset ...
随机推荐
- 软件测试技术作业3---PrintPrimes()
一.代码部分: private static void printPrimes (int n) { int curPrime; // Value currently considered for pr ...
- logstash5.x安装及简单运用
Logstash requires Java 8. Java 9 is not supported. 1.检测是否安装了java环境 [root@node3 ~]# java -version jav ...
- 5309 《Java程序设计》第6周学习总结
教材学习内容总结 输入与输出 InputStream与OutputStream 从应用程序角度来看,如果要将数据从来源取出,可以使用输入串流:如果要将数据写入目的地,可以使用输出串流.在Java中,输 ...
- T-shirt again
T-shirt again 标签(空格分隔): 软工实践 第一次获得小黄裳是在大一下的C++课上,见T-shirt 0.0... 这次在软工课上能再次获得小黄裳,是我没有想到的,个人觉得里面有蛮多的运 ...
- ubuntu文字界面与图形界面切换
redhat: (据说是) 图形界面->文字界面:crtl+alt+F1~6 文字界面->图形界面:crtl+alt+F7 -------------------------------- ...
- 比较字符串CompareTo的用法及注意
CompareTo用法 static void Main(string[] args) { string str = "1"; ...
- sbt安装与配置
下载地址:http://www.scala-sbt.org/download.html 当前版本:sbt-0.13.13.tgz 安装 1.解压并赋予权限 [root@hidden util]# ta ...
- Redis维护
关闭redis [root@--x-x log]# cd /usr/local/redis/bin/ [root@--x-x bin]# ./redis-cli -h shutdown 启动redis ...
- oracle的 分表 详解 -----表分区
此文从以下几个方面来整理关于分区表的概念及操作: 1.表空间及分区表的概念 2.表分区的具体作用 3.表分区的优缺点 4.表分区的几种类 ...
- The OAuth 2.0 Authorization Framework: Bearer Token Usage
https://tools.ietf.org/html/rfc6750 1.2. Terminology Bearer Token A security token with the property ...