继上一篇博文,这篇博文继续学习window对象,兄弟,挺住!!
窗口关系和框架
与top相对的window对象是parent。 parent对象始终指向框架的直接最上层框架。在某些情况下,parent可能等于top,但在没有框架时,parent一定等于top(此时它们都是window对象)。
frameset.html见javascript三大模块之一:BOM(浏览器对象模型)—window(一)。
右侧yetanoherframeset.html如下:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title></title>
<link rel="stylesheet" href="">
</head>
<frameset cols="50%,50%">
<frame src="red.html" name="redFrame"></frame>
<frame src="blue.html" name="blueFrame"></frame>
</frameset>
</html>
加载过程:
浏览器在加载完第一个框架集之后,会继续将第二个框架集加载到rightFrame中。
如果代码位于redFrame(或blueFrame),那么parent对象指向的就是rightFrame。
如果代码位于topFrame中,则parent指向top,因为topFrame的直接上层框架就是最外层框架。
注意:
除非最高层的框架是window.open()打开的,否则window对象的name属性不包含任何值。
self对象
与框架有关的最后一个对象self,它始终指向window;实际上,self和window对象可以互换使用。
self的目的
引入self对象的目的=只是为了与top和parent对象对应起来,因此它不格外包含其他值。
所有这些对象都是window对象,可以通过window.top、window.parent等形式来访问。
不同层次的window对象可以连缀起来。如window.parent.parent.frames[0]。
- 在使用框架过程中,浏览器会存在多个Global对象。
- 在每个框架中定义的全局变量都hi自动变成window对象的属性。
- 由于每个window对象都包含原生类型的构造函数,因此每个框架都有一套自己的构造函数,这些构造函数意义对应,但是不相等。 例如:
top.Object并不等于top.frames[0].Object。
- 这个问题会影响到对跨框架传递的对象使用instanceof操作符。