【问题标题】:use setTimeout with showModalDialog in chrome will block the tab在 chrome 中使用 setTimeout 和 showModalDialog 将阻止选项卡
【发布时间】:2012-06-08 08:18:04
【问题描述】:

我需要一个带有 setTimeout 的 ShowModalDialog 的功能,所以我测试一下弹出窗口 和谷歌浏览器中的 ModalDialog 我遇到了一些问题。 页面加载上有两个弹出窗口。一个由 winodw.open() 打开, 另一个由 window.showmodaldialog() 像这样打开:

setTimeout(function(){window.open("PopupWindow.html","_blank","")},100);
setTimeout(function(){window.showModalDialog("ModalDialog.html","","")},100)};

打开两个弹出窗口后,我单击 PupupWindow.html 上的一个按钮。它会调用 函数如下:

function test()
{
  setTimeout(function(){alert("test");},1000);
}

在 Google Chrome 14 中运行良好。在我将 Google Chrome 更新到版本 19 后, PopupWindow.html 将在调用 test() 时挂起,直到 ModalDialog.html 关闭。 请告诉我为什么这个案例在 Google Chrome 19 或任何方式上都被破坏了 showModalDialog 和 Google Chrome 19 上的 window.open()。感谢您的帮助。

【问题讨论】:

    标签: javascript google-chrome settimeout window.open showmodaldialog


    【解决方案1】:

    新版 Chrome 实际上表现出正确的行为。我在 Safari 和 Firefox 中也会发生同样的行为。

    模态对话框本质上应该阻止用户在完成模态对话框之前与应用程序的其余部分进行交互。

    Chrome 一直被许多无法正确处理的问题所困扰。有关一些示例,请参阅 http://code.google.com/p/chromium/issues/detail?id=4202http://code.google.com/p/chromium/issues/detail?id=16045http://code.google.com/p/chromium/issues/detail?id=42939。如果您遇到不同的行为,他们似乎终于开始清理其中的一些。

    通常应避免使用 window.showModalDialog,原因有很多,我在此详述 - http://tjvantoll.com/2012/05/02/showmodaldialog-what-it-is-and-why-you-should-never-use-it/

    如果您需要模态对话框,我强烈推荐jQuery UI's dialog plugin

    【讨论】:

      猜你喜欢
      • 2021-06-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多