window.parent与window.opener的区别 javascript调用主窗口方法

1:   window.parent 是iframe页面调用父页面对象

举例:

a.html

<html>
<head><title>父页面</title></head>
<body>
<form name="form1" id="form1">

<input type="text" name="username" id="username"/>

</form>
<iframe src="b.html" width=100%></iframe>
</body>
</html>

如果我们需要在b.htm中要对a.htm中的username文本框赋值,就如很多上传功能,上传功能页在Ifrmae中,上传成功后把上传后的路径放入父页面的文本框中

我们应该在b.html中写
<script type="text/javascript">
var _parentWin = window.parent ;
_parentWin.form1.username.value = "xxxx" ;
</script>


实例地址:  http://www.cnspry.cn/blog/attachments/window.parent实例/a.html

2:   window.opener 是window.open 打开的子页面调用父页面对象

实例地址:  http://www.cnspry.cn/blog/attachments/window.opener实例/a.html

opener:对打开当前窗口的window对象的引用,如果当前窗口被用户打开,则它的值为null.

self:自引用属性,是对当前window对象的应用,与window属性同义.

self代表自身窗口,opener代表打开自身的那个窗口,比如窗口A打开窗口B.如果靠window.open方法,则对于窗口B,self代表B自己,而opener代表窗口A.



来源:http://www.cnspry.cn/blog/article.asp?id=18

posted @ 2008-07-12 11:05  hemingchen  阅读(4109)  评论(1编辑  收藏  举报