Alert Box Protection

Submitted by:Tim Kelly

Date added:03 April, 2011


Often when working on scripts alert boxes are placed inside loops as a debugging tool. You can sometimes end up with hundreds of alert boxes and no way to stop them. This script placed at the start of your code will give you an option to disable the alert boxes after a pre-determined number set by you.

Tags: alert box , debugging tool

Code Snippet:

<!-- Add this snippet to the beginning of your code for testing purposes.  -->

var a=window.alert, c=0;
// Change the number below to the number of alert boxes to display before the warning is given.
if (++c%5==0) {
if (!confirm(q+'\nThere have been '+c+' alert boxes, continue displaying them?')) window.alert=function(){};
} else a(q);

// This is only a test case. You can removed it.
for (var i=1; i<50; i++) {
alert('This is an annoying loop of 50 alerts.\nEvery 5th alert you will have an option to exit.\n\n'+i);