使用window.open以防镀铬

use window.open in case of chrome

本文关键字:window open 使用      更新时间:2023-09-26

由于window.showModalDialog在chrome上不起作用,我在firefoxchrome中使用它,但我的问题是window.open的返回值未定义,可能是因为javascript在我关闭子窗口之前仍在继续,所以我试图将代码置于if (returnValue.closed)的这种条件下。。但问题是子窗口一直在加载,我无法从中选择我的值。

这是我的代码:

if (window.showModalDialog) {
   var retVal = window.showModalDialog(...)
if (!window.showModalDialog) {
 var retVal = window.open(...);
            while (a == 0) {
                if (retVal.onload()) {
                    if (retVal.closed) {
                        if (retVal != null) {...
                        }
                    }
                }
        }
    }

非常感谢您的帮助。

showModalDialog是一个不推荐使用的功能。你可以看到http://blog.chromium.org/2014/07/disabling-showmodaldialog.html了解更多详细信息。

我建议你使用另一个javascript"popup"选项(从许多可用选项中),它也会"冻结"页面的其余部分,如:

  • https://github.com/niutech/showModalDialog对话框polyfill
  • http://getbootstrap.com/javascript/#modals-引导模式
  • http://jqueryui.com/dialog/#modal-确认-JQueryUI模式
  • 等等

您需要找到另一种方法将返回值传递回页面,具体取决于您选择使用的选项。