zoukankan      html  css  js  c++  java
  • 谷歌不兼容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事件进行调用方法就行

  • 相关阅读:
    83. Remove Duplicates from Sorted List
    35. Search Insert Position
    96. Unique Binary Search Trees
    94. Binary Tree Inorder Traversal
    117. Populating Next Right Pointers in Each Node II
    116. Populating Next Right Pointers in Each Node
    111. Minimum Depth of Binary Tree
    169. Majority Element
    171. Excel Sheet Column Number
    190. Reverse Bits
  • 原文地址:https://www.cnblogs.com/fengjiqiang/p/5190377.html
Copyright © 2011-2022 走看看