01/23/06
O ften 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.
W e have tested the script in IE6.0, Firefox1.5, Opera8.51, Netscape7.02, Netscape8.0.4 and AOL Explorer1.2. This script worked well in all platforms with one variation observed in AOL Explorer1.2.
D epending on your knowledge of HTML and javascripts, this is an easy one part copy and paste script that goes at the start of your code that you are debugging. It will give you an option to disable the alert boxes after a pre-determined number set by you. You can also reconfigure the text you see as the box appears.
T he first reconfiguration is that of how many annoying alerts you will receive before you can cancel them.
Default Number Of Alerts
(function(){
var a=window.alert, c=0;
window.alert=function(q){
// Change the number below to the number of alert boxes to display before the warning is given.
if (++c%5==0) {
A s you can clearly notice in the above section, it tells you where to change the number of alert boxes before you can continue them or cancel them.
Default Text To Appear
if (++c%5==0) {
if (!confirm(q+'\nThere have been '+c+' alert boxes, continue displaying them?')) window.alert=function(){};
} else a(q);
}
})();
F or this tutorial, as you can notice, there is a test button. In the snipplet of code you get, this is nonexistent for obvious reasons. The button, when selected is showing you what you will see if the snipplet of code locates a bug in your script. Also, on the site you get the code there is one part that you can remove and is clearly documented.
<!------ You Can Remove From Here Down ------>
// 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);
}
I
f you would like to get this snipplet of code to assist you in debugging scripts, grab the respective below link and you are there. We hope our tutorial was easy to follow and we covered everything in detail. If you have any problems with this or anything else, feel free to consult our [ FAQ ] and if you can't find the answer there, [ contact us ].
[ Get Code Here ]
[ Rate This Page ]