首頁  >  問答  >  主體

javascript - chrome 沒有showModalDialog方法怎麼辦

在訪問一些路由器設定頁面的時候,由於比較老,chrome竟然無法正常彈出設定窗口,
console裡報錯:showModalDialog方法不存在

PHP中文网PHP中文网2642 天前767

全部回覆(1)我來回復

  • PHP中文网

    PHP中文网2017-07-05 10:42:22

    直接把對應的showModalDialog方法改成open就可以了

    另stackoverflow上的程式碼,但是有時候不行

    <script type="text/javascript">
      // fix for deprecated method in Chrome 37
      if (!window.showModalDialog) {
         window.showModalDialog = function (arg1, arg2, arg3) {
    
            var w;
            var h;
            var resizable = "no";
            var scroll = "no";
            var status = "no";
    
            // get the modal specs
            var mdattrs = arg3.split(";");
            for (i = 0; i < mdattrs.length; i++) {
               var mdattr = mdattrs[i].split(":");
    
               var n = mdattr[0];
               var v = mdattr[1];
               if (n) { n = n.trim().toLowerCase(); }
               if (v) { v = v.trim().toLowerCase(); }
    
               if (n == "dialogheight") {
                  h = v.replace("px", "");
               } else if (n == "dialogwidth") {
                  w = v.replace("px", "");
               } else if (n == "resizable") {
                  resizable = v;
               } else if (n == "scroll") {
                  scroll = v;
               } else if (n == "status") {
                  status = v;
               }
            }
    
            var left = window.screenX + (window.outerWidth / 2) - (w / 2);
            var top = window.screenY + (window.outerHeight / 2) - (h / 2);
            var targetWin = window.open(arg1, arg1, 'toolbar=no, location=no, directories=no, status=' + status + ', menubar=no, scrollbars=' + scroll + ', resizable=' + resizable + ', copyhistory=no, width=' + w + ', height=' + h + ', top=' + top + ', left=' + left);
            targetWin.focus();
         };
      }
    </script>

    回覆
    0
  • 取消回覆