忽略对'alert()'的调用。文档被沙盒化,'allow-modals'关键字未被设置 [英] Ignored call to 'alert()'. The document is sandboxed, and the 'allow-modals' keyword is not set

查看:3732
本文介绍了忽略对'alert()'的调用。文档被沙盒化,'allow-modals'关键字未被设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每当在JSFiddle中运行 alert('something')时,都会收到错误信息:


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


在控制台中。



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



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

解决方案

IFrame沙箱技术有助于保护从外部内容创建似乎来自主网站混淆弹出窗口。要允许警报弹出窗口,您需要查找iframe标记,并修改沙箱属性以包含allow-modals值。对于JSFiddle,这是名为result的iframe。您需要在修改标签后重新运行(ctrl-enter)您的小提琴。

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



由此可见:

 < iframe name =result sandbox =allow-forms allow-popups allow-scripts allow-same-originframeborder =0> 

至此:

 < iframe name =resultsandbox =allow-modals allow-forms allow-popups allow-scripts allow-same-originframeborder =0> 

下面的TamperMonkey片段似乎很好地解决了这个问题:

  // == UserScript == 
// @name启用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';
});


Whenever running alert('something') in JSFiddle, I get the error:

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

in the console.

I cannot find any information on this error through Google.

How do I fix this? What is, and where can I set, the 'allow-modals' keyword?

解决方案

IFrame sandboxing is a technique that helps protect from outside content creating confusing popups that would appear to come from the main website. To allow alert popups you will need to find the iframe tag, and modify the sandbox attribute to contain the allow-modals value. For JSFiddle this is the iframe named "result". You will need to Re-Run (ctrl-enter) your Fiddle after modifying the tag.

Using web browser Developer Tools or something like Grease Monkey/Tamper Monkey change the iframe.

From this:

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

To this:

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

The following TamperMonkey snippet seems to do the trick nicely:

// ==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';
});

这篇关于忽略对'alert()'的调用。文档被沙盒化,'allow-modals'关键字未被设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆