js opener 的使用

注意:测试时请部署到web服务器,即,以 http://** 的形式打开

在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错误。
 
例子
--------------------------------
opener.html
--------------------------------
<html>
<body>
<form name=form1>
<input type=text name=inpu >
<input type=button  οnclick="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=# οnclick="{opener.document.form1.inpu.value+='孙超,';}">添加</a>
</form>
</body>
</html>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值