javascript中的window.opener讲解

定义和用法

opener 属性是一个可读可写的属性,可返回对创建该窗口的 Window 对象的引用。

opener 属性非常有用,创建的窗口可以引用创建它的窗口所定义的属性和函数。

语法

window.opener

提示和注释

注释:只有表示顶层窗口的 Window 对象的 operner 属性才有效,表示框架的 Window 对象的 operner 属性无效。

 

实例:

下面例子展示了如何打开一个孩子的窗口和打开的窗口和孩子之间的沟通:

    父页面:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
  <head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>load</title>
  </head>
  <body>
	 先用这个按钮打开一个窗口:
    <button id="childOpener" οnclick="OpenChildWindow ();">打开子窗口!</button>
    <br /><br />
    您可以更改子窗口的选择列表中按钮的文本颜色。

	 <script type="text/javascript">
        function OpenChildWindow() {
            window.open ("childWindow.html", "OpenerTest", "width=300, height=200");
        }
    </script>
  </body>
</html>

    子页面:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
  <head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  </head>
  <body>
	
	改变按钮的颜色在开启窗口:
    <select οnchange="ChangeOpener (this)">
        <option />black
        <option />red
        <option />blue
        <option />green
    </select>


	<script type="text/javascript">
        function ChangeOpener(selectTag) {
            var openerWindow = window.opener;
			if(openerWindow != null){
				var button = openerWindow.document.getElementById("childOpener");
				button.style.color = selectTag.options[selectTag.selectedIndex].text;
			}  
        }
    </script>
  </body>
</html>

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值