JavaScript中 window.parent 、window.top、window.self代表的含义
2014-10-29 10:32
363 查看
在应用有frameset或者iframe的页面时,parent是父窗口,top是最顶级父窗口(有的窗口中套了好几层frameset或者iframe),self是当前窗口, opener是用open方法打开当前窗口的那个窗口。
在项目中,有如下应用场景,原本在右侧iframe中引入对话框js类,对话框能出来但是只能在右侧iframe中移动,不能在整个页面内移动。
解决如下:
将对话框js类引入到最外层jsp中,然后在原调用出,使用
此次window.top是最顶级父窗口含义。
下面实例:
top作用是取得最顶层框架对象
A.html
[/code]
B.html
[/code]
C.html
[/code]
b.html中的top=parent c.html中的top=parent.parent
<摘自:http://wangpj.iteye.com/blog/853395 & http://blog.csdn.net/good_youth/article/details/2079416>
在项目中,有如下应用场景,原本在右侧iframe中引入对话框js类,对话框能出来但是只能在右侧iframe中移动,不能在整个页面内移动。
解决如下:
将对话框js类引入到最外层jsp中,然后在原调用出,使用
new window.top.SGS.UI.Control.CommDialog(); window.top.document.body.appendChild(_dialog.divObj);
此次window.top是最顶级父窗口含义。
下面实例:
top作用是取得最顶层框架对象
A.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
[/code]
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>prototype test</title>
</head>
<body>
<iframe src="b.html"></iframe>
<script language="javascript">
var topstr = "my top";
alert(a.html='+top.location.href);
</script>
</body>
</html>
B.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
[/code]
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>prototype test</title>
</head>
<body>
<iframe src="c.html"></iframe>
<script language="javascript">
alert('b.html='+top.location.href+";a.html.topstr="+top.topstr);//top.topstr可取a.html(顶层框架参数)的topstr变量
</script>
</body>
</html>
C.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
[/code]
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>prototype test</title>
</head>
<body>
<script language="javascript">
alert('c.html='+top.location.href+";a.html.topstr="+top.topstr);//top.topstr可取a.html(顶层框架参数)的topstr变量
</script>
</body>
</html>
b.html中的top=parent c.html中的top=parent.parent
<摘自:http://wangpj.iteye.com/blog/853395 & http://blog.csdn.net/good_youth/article/details/2079416>
相关文章推荐
- Javascript 中的window.parent ,window.top,window.self 详解
- Javascript中的window.parent ,window.top,window.self 详解
- JavaScript中的window.parent ,window.top,window.self 等等
- 通过<frameset>和<iframe>看JavaScript中window对象parent、self、top的区别
- Js中的window.parent ,window.top,window.self 代表的对象
- window.parent ,window.top,window.self 详解
- Js中的window.parent ,window.top,window.self 详解 .
- JSP中window、parent、top、self详解
- Js中的window.parent ,window.top,window.self详解
- window.parent ,window.top,window.self 详解
- Js中的window.parent ,window.top,window.self 详解
- ☀【window.self / window.parent / window.top】
- Js中的window.parent ,window.top,window.self 详解
- Js中的window.parent ,window.top,window.self 详解
- javascript中的top与self.parent问题解决小记
- Js中的window.parent ,window.top,window.self 详解
- Js中的window.parent ,window.top,window.self 详解
- Js中的window.parent ,window.top,window.self
- Js中的window.parent ,window.top,window.self
- Js中的window.parent ,window.top,window.self 详解