Skip to content

Commit

Permalink
Remove alerts only during load - put them back in to allow user to in…
Browse files Browse the repository at this point in the history
…teract and get alerts. Fixes #148
  • Loading branch information
remy committed Apr 18, 2012
1 parent 6cfd94d commit 6d765fa
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
3 changes: 1 addition & 2 deletions index.php
Expand Up @@ -132,8 +132,7 @@
<strong>Output</strong>
<span class="options">
<button id="runwithalerts" title="ctrl + enter
Include alerts, prompts &amp; confirm boxes">Run JavaScript</button>
<label>Always run JS<input type="checkbox" id="enablejs"></label>
Include alerts, prompts &amp; confirm boxes">Run JS with alerts</button> <label>Always run JS<input type="checkbox" id="enablejs"></label>
</span>
</div>
</div>
Expand Down
9 changes: 6 additions & 3 deletions js/render/live.js
@@ -1,7 +1,9 @@
var $live = $('#live'),
$body = $('body'),
showlive = $('#showlive')[0],
throttledPreview = throttle(renderLivePreview, 200);
throttledPreview = throttle(renderLivePreview, 200),
killAlerts = '<script>try{window.print=function(){};window.alert=function(){};window.prompt=function(){};window.confirm=function(){};}catch(e){}</script>',
restoreAlerts = '<script>try{delete window.print;delete window.alert;delete window.prompt;delete window.confirm;}catch(e){}</script>';

var iframedelay = (function () {
var iframedelay = { active : false },
Expand Down Expand Up @@ -69,9 +71,9 @@ function renderLivePreview(withalerts) {
// nullify the blocking functions
// IE requires that this is done in the script, rather than off the window object outside of the doc.write
if (withalerts !== true) {
doc.write('<script>try{window.print=function(){};window.alert=function(){};window.prompt=function(){};window.confirm=function(){};}catch(e){}</script>');
doc.write(killAlerts);
} else {
doc.write('<script>try{delete window.print;delete window.alert;delete window.prompt;delete window.confirm;}catch(e){}</script>');
doc.write(restoreAlerts);
}

if (jsbinConsole) {
Expand Down Expand Up @@ -101,6 +103,7 @@ function renderLivePreview(withalerts) {
};

doc.write(source);
doc.write(restoreAlerts);
}
doc.close();
delete jsbin.panels.panels.live.doc;
Expand Down

0 comments on commit 6d765fa

Please sign in to comment.