忽略了对 'alert()' 的调用。文档已沙盒化,未设置 'allow-modals' 关键字

Ignored call to 'alert()'. The document is sandboxed, and the 'allow-modals' keyword is not set

每当 运行 alert('something') 在 JSFiddle 中,我得到错误:

Ignored call to 'alert()'. The document is sandboxed, and the 'allow-modals' keyword is not set.

在控制台中。

我无法通过 Google 找到有关此错误的任何信息。

我该如何解决这个问题? 'allow-modals' 关键字是什么,我可以在哪里设置?

JSFiddle 必须更改其 iframes 以添加 sandbox 属性。或者Chrome一定是添加了支持allow-modals.

实际上,对于 Chrome 46 岁以上的人来说这是新的:

IFrame 沙盒技术有助于防止外部内容创建看似来自主网站的令人困惑的弹出窗口。要允许警报弹出窗口,您需要找到 iframe 标记,并修改 sandbox 属性以包含 allow-modals 值。对于 JSFiddle,这是名为 "result" 的 iframe。修改标签后,您需要重新运行(ctrl-enter)您的Fiddle。

使用网络浏览器开发工具或 Grease 之类的工具 Monkey/Tamper Monkey 更改 iframe。

来自这里:

<iframe name="result" sandbox="allow-forms allow-popups allow-scripts allow-same-origin" frameborder="0">

为此:

<iframe name="result" sandbox="allow-modals allow-forms allow-popups allow-scripts allow-same-origin" frameborder="0">

以下 TamperMonkey 片段似乎可以很好地解决问题:

// ==UserScript==
// @name         Enable alert()s
// @match        //jsfiddle.com/*
// @require      http://code.jquery.com/jquery-latest.min.js
// @grant        unsafeWindow
// ==/UserScript==
this.$ = this.jQuery = jQuery.noConflict(true);
$("iframe[name='result']").each(function() {
    this.sandbox += ' allow-modals';
});