谷歌不兼容showModalDialog()方法出現對話窗口解決方法


      javascript中showModalDialog()方法在IE,火狐,百度,360等瀏覽器可以使用,但是在谷歌瀏覽器下去沒有任何反應,現在我給大家一種方法,當然這個方法是我在網上找的,調試可以使用。

<script type="text/javascript">
        //開啟模式窗口
        function showMyModal() {
            var url = "SelectUser.aspx";
            //傳入參數示例

            var modalReturnValue = myShowModalDialog(url, window, 300, 500);
            //alert(modalReturnValue.name);
            //窗口關閉后執行某些方法
            //TODO sth
        }
        //彈出框google Chrome執行的是open
        function myShowModalDialog(url, args, width, height) {
            var tempReturnValue;
            if (navigator.userAgent.indexOf("Chrome") > 0) {
                var paramsChrome = 'height=' + height + ', width=' + width + ', top=' + (((window.screen.height - height) / 2) - 50) +
                    ',left=' + ((window.screen.width - width) / 2) + ',toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, status=no';
                window.open(url, "newwindow", paramsChrome);
            }
            else {
                var params = 'dialogWidth:' + width + 'px;dialogHeight:' + height + 'px;status:no;dialogLeft:'
                            + ((window.screen.width - width) / 2) + 'px;dialogTop:' + (((window.screen.height - height) / 2) - 50) + 'px;';
                tempReturnValue = window.showModalDialog(url, args, params);
            }
            return tempReturnValue;
        }
    </script>

最后想要點擊就可以出現對話框就行,只需要使用onclick事件進行調用方法就行


免責聲明!

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



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