JS產生模態窗口,關閉后刷新父窗體。(兼容各瀏覽器)


折騰了好久,終於搞出來了。參考資料

http://www.cnblogs.com/davidyang78/archive/2011/07/29/2121278.html

下面直接上源碼,保證兼容ie,google,360,firefox

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
    <!--防止模態窗口提交form時再彈出一個新窗口-->
    <base target="_self" />
    <script type="text/javascript">
        function DialogWin(url, width, height) { height = height + 50; if (url.indexOf('.aspx?', 0) > 0) { url = url + '&t=' + Math.random(); } else { url = url + '?&t=' + Math.random(); } return window.showModalDialog(url, window, ";dialogWidth:" + width + "px;dialogHeight:" + height + "px;center:1;scroll:auto;help:0;status:0;statusbars:0;location:0;menubar:0;toolbars:0;resizable:0;"); }
        function openClick() {
            var result = DialogWin("HtmlPage1.html", 500, 300);
            if (typeof (result) == 'undefined') {
                result = window.ReturnValue;
            }
            if (result==true) {
                window.location = window.location;
            }
        }
    </script>

</head>
<body>
    <input type="button" id="btnSub" onclick="openClick()" value="彈出" />
</body>
</html>
父窗體

 

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title></title>
    <!--防止模態窗口提交form時再彈出一個新窗口-->
    <base target="_self" />
    <script type="text/javascript">
        if (typeof (window.opener) == 'undefined')
            window.opener = window.dialogArguments;
        function sureClick() {
            window.retureValue = true;
            if (window.opener && window.opener != null) {
                window.opener.ReturnValue = true;
            }
            window.close();
        }
    </script>

</head>
<body>
    <input type="button" id="btnSub" onclick="sureClick()" value="確定" />
</body>
</html>
子窗體

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM