Permalink
Browse files

Remove alerts only during load - put them back in to allow user to in…

…teract and get alerts. Fixes #148
  • Loading branch information...
1 parent 6cfd94d commit 6d765facf7dc304deb4f0c7d031efc9aa98e2f23 @remy remy committed Apr 18, 2012
Showing with 7 additions and 5 deletions.
  1. +1 −2 index.php
  2. +6 −3 js/render/live.js
View
@@ -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>
View
@@ -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 },
@@ -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) {
@@ -101,6 +103,7 @@ function renderLivePreview(withalerts) {
};
doc.write(source);
+ doc.write(restoreAlerts);
}
doc.close();
delete jsbin.panels.panels.live.doc;

0 comments on commit 6d765fa

Please sign in to comment.