window.parent与window.opener的区别与使用

 2023-09-10 阅读 16 评论 0

摘要:1、window.parent 是iframe页面调用父页面对象 举例: a.html window.location。<html><head><title>A</title></head><body><form name="form1" id="form1"><input type="text" name=

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

举例: a.html

window.location。<html>
<head><title>A</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.html中要对a.html中的username文本框赋值(就如很多上传功能,上传功能页在ifrmae中,上传成功后把上传后的路径放入父页面的文本框中),我们应该在b.html中写:

<script type="text/javascript">
var _parentWin = window.parent;
_parentWin.form1.username.value = "xxxx";
</script>

window.open 新窗口。Z-Blog的文章编辑页面上传功能就是这么实现的。

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

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

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

举例:a.html

<input type="text" name="username" id="username"/>
<a οnclick="window.open(this.href,'','resizable=yes,width=800,height=600,status'); return false" href="b.html">B</a>

window。如果需要在b.html中对a.html中的表单元素赋值,我们应该在b.html中这么写

<a href="javascript:try{window.opener.document.getElementById('username').contentWindow.
frames[0].document.getElementsByTagName('body')[0].innerHTML+='xxx'}catch(e){};window.close();">插入</a>

在后面用window.close关闭b.html。WindsPhoto 2.7.3 中在文章编辑页面弹出新窗口(图片列表)后,选择插入已上传图片便是如此实现的。

window怎么使用、转载于:https://www.cnblogs.com/opaljc/archive/2012/09/17/2688950.html

版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。

原文链接:https://hbdhgg.com/2/35868.html

发表评论:

本站为非赢利网站,部分文章来源或改编自互联网及其他公众平台,主要目的在于分享信息,版权归原作者所有,内容仅供读者参考,如有侵权请联系我们删除!

Copyright © 2022 匯編語言學習筆記 Inc. 保留所有权利。

底部版权信息