技术共享
技术共享 Technology sharing 当前位置:首页->技术共享->技术共享

window.opener 返回的是创建当前窗口的那个窗口的引用,比如点击了a.htm上的一个链接而打开了b.htm,然后我们打算在b.htm上输入一个值然后赋予a.htm上的一个id为“name”的textbox中,就可以写为:
window.opener.document.getElementById(“name”).value="输入的数据"
 

<html>
<body>
<form name=form1>
<input type=text name=inpu >
<input type=button onclick="javascript:window.open('back2opener.html?toname=opener.form1.inpu');">
</form>
</body>
</html>


--------------------------------
back2opener.html
--------------------------------
<html>
<body>
<form name=form1>
<input type=text name=inpu >

<a class=under href=# onclick="{opener.document.form1.inpu.value ='孙超,';}">添加</a>
</form>
</body>
</html>

 

     在JS中,window.opener只是对弹出窗口的母窗口的一个引用。比如:a.html中,通过点击按钮等方式window.open出一个新的窗口b.html。那么在b.html中,就可以通过window.opener(省略写为opener)来引用a.html,包括a.html的document等对象,操作a.html的内容。
     假如这个引用失败,那么将返回null。所以在调用opener的对象前,要先判断对象是否为null,否则会出现“对象为空或者不存在”的JS错误。




上一篇:smarty生成静态网页
下一篇:php缩略图函数