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

23,608

Solution 1

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

Solution 2

That is something JSFiddle must have changed to its iframes to add the sandbox attribute. Or Chrome must have added support allow-modals.

Actually it is something new for Chrome 46+:

Share:
23,608
ᔕᖺᘎᕊ
Author by

ᔕᖺᘎᕊ

I'm in my second year of uni in the UK. I'm interested in html, php, javascript, jquery, node.js, python, css, and flutter. I LOVE Chuck!! :D If you need to get in touch with me, see my website for more details. Userscripts I've made some userscripts for the Stack Exchange sites you may be interested in: My SOOF userscript, now Stack Overflow Extras, has a bunch of optional features you can add to 'enhance' SE (examples of these features are: pre-defined edit reasons; side-by-side post editing; highlight answerer's names in comments, and so on) My SE WYSIWYG Editor userscript adds a WYSIWYG (What You See Is What You Get) Editor to Stack Exchange - definitely worth a try! :) My Freehand Circles Drawing Tool userscript allows you to draw directly onto images you see on SE sites - you can change the brush colour and width to draw anything you might want - it's great fun, useful and easy to use :) My Self Destructing Comments userscript allows you to set a date at which a comment you wrote should be deleted - useful for those 'comment cleanup', 'thanks', or 'welcome' comments. My SE Desktop Notifications userscript shows desktop notifications whenever there is new activity on a question open in a new tab - useful for keeping track of questions without having to scroll through the answers to see if there is a new edit, or comment, or score change :) See many more at my Stack Apps profile :) ǝɯɐuɹǝsn ʎɯ ɹoɟ ɯoɔ˙sloqɯʎsɟ˙ʍʍʍ oʇ sʞuɐɥʇ

Updated on October 22, 2020

Comments

  • ᔕᖺᘎᕊ
    ᔕᖺᘎᕊ over 3 years

    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?