Javascript 为什么警告框中会出现“阻止此页面创建其他对话框”?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5848381/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 19:11:08  来源:igfitidea点击:

Why "Prevent this page from creating additional dialogs" appears in the alert box?

javascripthtmlruby-on-railsalertfirefox4

提问by Misha Moroshko

In my Rails 3 application I do:

在我的 Rails 3 应用程序中,我这样做:

render :js => "alert(\"Error!\nEmpty message sent.\");" if ...

Sometimes, below this error message (in the same alert box) I see: "Prevent this page from creating additional dialogs" and a checkbox.

有时,在此错误消息下方(在同一个警报框中),我会看到:“防止此页面创建其他对话框”和一个复选框。

What does this mean ?

这是什么意思 ?

Is that possible not to display this additional text and checkbox ?

是否可以不显示此附加文本和复选框?

I use Firefox 4.

我使用 Firefox 4。

回答by Marcel Korpel

It's a browser feature to stop websites that show annoying alert boxes over and over again.

这是一个浏览器功能,可以阻止网站一遍又一遍地显示烦人的警报框。

As a web developer, you can't disable it.

作为 Web 开发人员,您无法禁用它。

回答by Pekka

What does this mean ?

这是什么意思 ?

This is a security measure on the browser's end to prevent a page from freezing the browser (or the current page) by showing modal (alert / confirm) messages in an infinite loop. See e.g. herefor Firefox.

这是浏览器端的一种安全措施,通过在无限循环中显示模式(警报/确认)消息来防止页面冻结浏览器(或当前页面)。参见例如此处的 Firefox。

You can not turn this off. The only way around it is to use custom dialogs like JQuery UI's dialogs.

您无法关闭此功能。解决它的唯一方法是使用自定义对话框,如JQuery UI 的对话框

回答by Arun

You can create a custom alert box using java script, below code will override default alert function

您可以使用 java 脚本创建自定义警报框,以下代码将覆盖默认警报功能

window.alert = function(message) { $(document.createElement('div'))
    .attr({
      title: 'Alert',
      'class': 'alert'
    })
    .html(message)
    .dialog({
      buttons: {
        OK: function() {
          $(this).dialog('close');
        }
      },
      close: function() {
        $(this).remove();
      },
      modal: true,
      resizable: false,
      width: 'auto'
    });
};

回答by mozey

Using JQuery UI's dialogsis not always a solution. As far as I know alert and confirm is the only way to stop the execution of a script at a certain point. As a workaround we can provide a mechanism to let the user know that an application needs to call alert and confirm. This can be done like this for example (where showError uses a jQuery dialog or some other means to communicate with the user):

使用JQuery UI 的对话框并不总是一个解决方案。据我所知,警报和确认是在某个点停止执行脚本的唯一方法。作为一种解决方法,我们可以提供一种机制让用户知道应用程序需要调用警报和确认。例如,这可以像这样完成(其中 showError 使用 jQuery 对话框或其他一些方式与用户通信):

var f_confirm;
function setConfirm() {
  f_confirm = confirm;
  confirm = function(s) {
    try {
      return f_confirm(s);
    } catch(e) {
      showError("Please do not check 'Prevent this page from creating additional dialogs'");
    }
    return false;
  };
};

回答by Queue

I designed this function to hopefully circumvent the checkbox in my web apps.

我设计了这个函数来希望绕过我的网络应用程序中的复选框。

It blocks all functionality on the page while executing (assuming fewer than three seconds has passed since the user closed the last dialog), but I prefer it to a recursive or setTimeout function since I don't have to code for the possibility of something else being clicked or triggered while waiting for the dialog to appear.

它在执行时阻止页面上的所有功能(假设自用户关闭最后一个对话框以来已经过去了不到三秒),但我更喜欢它而不是递归或 setTimeout 函数,因为我不必为其他事情的可能性进行编码在等待对话框出现时被点击或触发。

I require it most when displaying errors/prompts/confirms on reports that are already contained within Modalbox. I could add a div for additional dialogs, but that just seems too messy and unnecessary if built-in dialogs can be used.

在 Modalbox 中已包含的报告上显示错误/提示/确认时,我最需要它。我可以为其他对话框添加一个 div,但如果可以使用内置对话框,这似乎太混乱和不必要了。

Note that this would probably break if dom.successive_dialog_time_limit is changed to a value greater than 3, nor do I know if Chrome has the the same default as Firefox. But at least it's an option.

请注意,如果 dom.successive_dialog_time_limit 更改为大于 3 的值,这可能会中断,我也不知道 Chrome 是否具有与 Firefox 相同的默认值。但至少这是一个选择。

Also, if anyone can improve upon it, please do!

另外,如果有人可以改进它,请做!

// note that these should not be in the global namespace
var dlgRslt,
    lastTimeDialogClosed = 0;

function dialog(msg) {
    var defaultValue,
        lenIsThree,
        type;

    while (lastTimeDialogClosed && new Date() - lastTimeDialogClosed < 3001) {
        // timer
    }

    lenIsThree = 3 === arguments.length;
    type = lenIsThree ? arguments[2] : (arguments[1] || alert);
    defaultValue = lenIsThree && type === prompt ? arguments[1] : '';

    // store result of confirm() or prompt()
    dlgRslt = type(msg, defaultValue);
    lastTimeDialogClosed = new Date();
} 

usage:

用法:

dialog('This is an alert.');

dialog( 'This is a prompt', prompt );
dialog('You entered ' + dlgRslt);

dialog( 'Is this a prompt?', 'maybe', prompt );
dialog('You entered ' + dlgRslt);

dialog( 'OK/Cancel?', confirm );
if (dlgRslt) {
    // code if true
}

回答by zeppaman

This is a browser feature.

这是浏览器功能。

If you could, try to employ http://bootboxjs.com/, whit this library you can do the same of

如果可以,请尝试使用http://bootboxjs.com/,您可以使用此库执行相同的操作

alert("Empty message sent");

by writing:

通过写作:

bootbox.alert("Empty message sent", function(result) {
    // do something whit result
 });

You'll get a nice user interface too!

你也会得到一个漂亮的用户界面!