C#----记 window.showModalDialog遇到的问题

害~ 由于自己的小聪明 记一次自己的采坑

目前,新版本的chrome和opera、Firefox等浏览器已经不支持showModalDialog方法。

所以查了许久,找到一篇文章(点击打开),下面是代码

<script>
window.showModalDialog = function (url, arg, feature) { var opFeature = feature.split(";"); var featuresArray = new Array() if (document.all) { for (var i = 0; i < opFeature.length - 1; i++) { var f = opFeature[i].split("="); featuresArray[f[0]] = f[1]; } } else { for (var i = 0; i < opFeature.length - 1; i++) { var f = opFeature[i].split(":"); featuresArray[f[0].toString().trim().toLowerCase()] = f[1].toString().trim(); } } var h = "200px", w = "400px", l = "100px", t = "100px", r = "yes", c = "yes", s = "no"; if (featuresArray["dialogheight"]) h = featuresArray["dialogheight"]; if (featuresArray["dialogwidth"]) w = featuresArray["dialogwidth"]; if (featuresArray["dialogleft"]) l = featuresArray["dialogleft"]; if (featuresArray["dialogtop"]) t = featuresArray["dialogtop"]; if (featuresArray["resizable"]) r = featuresArray["resizable"]; if (featuresArray["center"]) c = featuresArray["center"]; if (featuresArray["status"]) s = featuresArray["status"]; var modelFeature = "height = " + h + ",width = " + w + ",left=" + l + ",top=" + t + ",model=yes,alwaysRaised=yes" + ",resizable= " + r + ",celter=" + c + ",status=" + s; var model = window.open(url, "", modelFeature, null); model.dialogArguments = arg; }
<script/>

需将这段代码放在页面的开头,然后发现解决问题

可是随着问题的解决 又出现了一个新的问题 那就是 IE 低版本的却不支持了

随即调了半天 想到一个方案  在页面加载时判断是否是 IE 如果是 就不执行上面代码  反则就执行

function isIE() { //ie?
            if (!!window.ActiveXObject || "ActiveXObject" in window) { }
            else { isOther(); }
        }

function isOther()
      {
    //上面的代码
     }

  转自:https://stackoverflow.com/questions/25663053/how-can-i-make-window-showmodaldialog-work-in-chrome-37

原文地址:https://www.cnblogs.com/wuyabaibsd/p/13185510.html