zoukankan      html  css  js  c++  java
  • js之open子父窗口传参(以及调用父页面方法等)

    父页面html代码

    <!
    DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> <script> var arr = new Array(); arr[0] = "test1"; arr[1] = "test2"; function openUrl() { var url = 'openChild.html'; var opts = 'height=400,width=800,left=200,top=200,toolbar=no,menubar=no,scrollbars=no, resizable=no,location=no, status=no'; window.open(url, "myChildWin", opts); } function setArr(value) { arr[2] = value; } function setDiv(v) { document.getElementById("mydiv").innerHTML = v; } </script> </head> <body> <input type='button' onclick=openUrl() name='test' value="click me "> <div id="mydiv"></div> <div id="mydiv2"></div> </body> </html>


    子页面html代码

    <!DOCTYPE html>
    <html>
    
        <head>
            <meta charset="UTF-8">
            <title></title>
            <script type="text/javascript" src="js/jquery.js" ></script>
            <script>
                function test() {
                    window.opener.setArr("test3");
                    var data = window.opener.arr;
                    document.write("成功获取父窗口定义的数据====" + data);
                    window.opener.setDiv("成功修改父窗口的div值llllll");
                    
                    //window.opener.document.getElementById("mydiv2").innerHTML="<font style='red'>通过opener.doucment直接修改</font>";
                    //window.opener.document.getElementById("mydiv2").style.color="yellow"; //可以生效 ,其中把opener改为parent后失效
                   $("#mydiv", window.opener.document).css("color","red"); //可以生效,其中把opener改为parent后失效
                }
            </script>
        </head>
    
        <body onload="test()">
            我是子窗口
        </body>
    
    </html>
    
    
    
     
  • 相关阅读:
    练习:使用nmcli 配置网络连接
    编辑网络配置文件
    ETCD安装
    LInux部署本地DNSbind9
    Linux 修改tomcat9相关参数优化
    Linux-编写SHELL 加密解密方法
    Jenkins的安装部署
    lepus 配置监控Mysql+Redis+Mongodb服务器
    lepus部署
    prometheus + grafana 安装 监控 redis mysql mongodb Linux服务器
  • 原文地址:https://www.cnblogs.com/rdchen/p/13183377.html
Copyright © 2011-2022 走看看