window.showModalDialog 子窗口数据回填父窗口

window.open 打开窗口时,能够很轻松的取得其父窗口。项目中须要用 showModalDialog打开窗口,想要取得父窗口值,并且还要在 open的基础上修改 为了避免让 window.returnValue 所返回的值不是那么烦索,就要想办法如何用showModalDialog 打开的窗口取得其父窗口。合理利用 showModalDialog 传入的参数即可以解决这个问题。javascript


话很少说,看例子:html


父窗口:a.htmljava

<html>
    <head>
        <script type="text/javascript" >
            function showDialog(){
                var param = "dialogWidth:400px;dialogHeight:300px;scroll:no;status:no;resizable:no";
                // 打开 b.html,并将当前 window作为参数传入弹出窗口中
                return window.showModalDialog("b.html", window, param);
            }
        </script>
        <title></title>
    </head>
    
    <body>
        <input type="button" value="弹出" onclick="showDialog()"/>
        <input type="text" value="父窗口值" name="farValue" id="farValue" />
    </body>
</html>


子窗口:b.htmlcode

<html>
    <head>
        <script type="text/javascript" >
            function getParValues(){
                // 接收父窗口传过的 window对象.
                var parWin= window.dialogArguments;
                parWin.document.getElementById("farValue").value = "子窗口改变的值";
            }
        </script>
        <title></title>
    </head>
    
    <body>
        <input type="button" value="改变父窗口值" onclick="getParValues()" />
    </body>
</html>


Done.htm

相关文章
相关标签/搜索