chrome 没有showModalDialog方法怎么办

在访问一些路由器设置页面的时候,由于比较老,chrome竟然无法正常弹出设置窗口,
console里报错:showModalDialog方法不存在

拉丁的传说
浏览 540回答 1
1回答

慕标琳琳

直接把对应的showModalDialog方法改成open就可以了另stackoverflow上的代码,但是有时候不起作用<script type="text/javascript">&nbsp; // fix for deprecated method in Chrome 37&nbsp; if (!window.showModalDialog) {&nbsp; &nbsp; &nbsp;window.showModalDialog = function (arg1, arg2, arg3) {&nbsp; &nbsp; &nbsp; &nbsp; var w;&nbsp; &nbsp; &nbsp; &nbsp; var h;&nbsp; &nbsp; &nbsp; &nbsp; var resizable = "no";&nbsp; &nbsp; &nbsp; &nbsp; var scroll = "no";&nbsp; &nbsp; &nbsp; &nbsp; var status = "no";&nbsp; &nbsp; &nbsp; &nbsp; // get the modal specs&nbsp; &nbsp; &nbsp; &nbsp; var mdattrs = arg3.split(";");&nbsp; &nbsp; &nbsp; &nbsp; for (i = 0; i < mdattrs.length; i++) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;var mdattr = mdattrs[i].split(":");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;var n = mdattr[0];&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;var v = mdattr[1];&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (n) { n = n.trim().toLowerCase(); }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (v) { v = v.trim().toLowerCase(); }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if (n == "dialogheight") {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; h = v.replace("px", "");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;} else if (n == "dialogwidth") {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; w = v.replace("px", "");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;} else if (n == "resizable") {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; resizable = v;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;} else if (n == "scroll") {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; scroll = v;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;} else if (n == "status") {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; status = v;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; var left = window.screenX + (window.outerWidth / 2) - (w / 2);&nbsp; &nbsp; &nbsp; &nbsp; var top = window.screenY + (window.outerHeight / 2) - (h / 2);&nbsp; &nbsp; &nbsp; &nbsp; 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);&nbsp; &nbsp; &nbsp; &nbsp; targetWin.focus();&nbsp; &nbsp; &nbsp;};&nbsp; }</script>
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript