zoukankan      html  css  js  c++  java
  • window.opener 子窗体操作父窗体

    以下是看到的一个例子:

    1.父窗体main.html:

     1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> 
     2 <HTML> 
     3 <head>
     4     <script type="text/javascript">
     5         function OpenChildWindow () {
     6             window.open ("sub.html", "OpenerTest", "width=300, height=200");
     7             //window.showModalDialog("sub.html", window);
     8         }
     9     </script>
    10 </head>
    11 <body>
    12     <button id="childOpener" onclick="OpenChildWindow();">Open child window!</button>
    13     <br /><br />
    14 </body>
    15 </HTML>

    2.子窗体sub.html:

     1 <!DOCTYPE html>
     2 <html>
     3 <head>
     4     <meta charset="utf-8" />
     5     <title>Modeless window example</title>
     6     <script type="text/javascript">
     7         function ChangeOpener (selectTag) {
     8             //if(window.opener == undefined) {
     9             //    alert("undefined");
    10             //}
    11             var openerWindow = window.opener;
    12             var button = openerWindow.document.getElementById ("childOpener");
    13             button.style.color = selectTag.options[selectTag.selectedIndex].text;
    14         }
    15     </script>
    16 <body>
    17     Change the color of the button in the opener window:
    18     <select onchange="ChangeOpener(this)">
    19         <option>black</option>
    20         <option>red</option>
    21         <option>blue</option>
    22         <option>green</option>
    23     </select>
    24 </body>
    25 </html>

    在chrome下折腾了一阵子,始终没有效果,IE、FF没问题,论坛中看到一位朋友解释如下(未测):

    “本地file浏览器测试不要用chrome(webkit核心的浏览器),不能互相操作”。

  • 相关阅读:
    如何查看ubuntu版本
    基于Python与命令行人脸识别项目(系列一)
    问题 B: Curriculum Vitae
    问题 M: 克隆玩具
    1906: 鹊桥相会
    3265: 聪明的矿工
    2363: 完美旗手队列
    2545: 内部收益率
    2544: 台球碰撞
    3272: 公民身份号码
  • 原文地址:https://www.cnblogs.com/hzz521/p/4262995.html
Copyright © 2011-2022 走看看