3

This may be dumb question. But somehow this engaged me for sometime and after some basic research I couldn't find an answer.

I was learning JavaScript and a code I wrote had an error and has been outputting infinite loops of alerts. I tried the normal shortcuts like Ctrl + C and Ctrl + Z but they didn't work. So I was thinking if there is any solution to this other than ending the browser process (like by doing a Ctrl + Alt + Del).

Jon Seigel
  • 12,251
  • 8
  • 58
  • 92
Christy John
  • 680
  • 6
  • 17
  • Yeah, going to Sarfaz's link and doing the SleighBoy's trick of constant Ok and F5 did the trick but had to patiently try for many times. – Christy John Mar 29 '10 at 14:29
  • Not putting it as an actual answer, 'cause I know I'll get voted down, but I solved this problem by switching to Chrome. :) It has a feature where if a page shows two or more alerts within a few seconds of each other it provides an option to suppress further alerts from that page. Very handy! – Toji Mar 29 '10 at 14:36

4 Answers4

1

There are workarounds, as @Sarfras mentions, but no magic button that'll save you. The F5 workaround is the best I know of.

Bialecki
  • 30,061
  • 36
  • 87
  • 109
0

If you are using firebug, I would suggest you look into using the log feature rather then alerts. Many people find this as a useful way of debugging.

http://getfirebug.com/logging

Shaunwithanau
  • 575
  • 5
  • 13
0

If you are using alert as a debugging method, I strongly suggest you use the firebug plugin. With it, you can use console.debug("whatever message", whatever, values).

Otherwise, if your intent is to actually use a dialog message, you could use some of these dialogs rather than the browser's built-in dialogs. Besides being a standard way of showing messages, they are way nicer ;)

Community
  • 1
  • 1
Pablo Cabrera
  • 5,749
  • 4
  • 23
  • 28
  • yeah, the grant idea is o move to firebug. but before that I need to get a basic understanding of JavaScript first. – Christy John Mar 29 '10 at 15:04
  • Unfortunately, I don't think there is a way out of this, although, on the Opera browser, every alert dialog as a small checkbox that lets you stop the javascript execution, so you can get out in these cases. Another possible way arround it, would be to overwrite the alert function, but still I wouldn't recommend that aswell. See http://stackoverflow.com/questions/1729501/javascript-overriding-alert/1730509#1730509 for details. – Pablo Cabrera Mar 29 '10 at 15:37
0

You can log errors without a specific browser, with a global array. This method allows you to 'turn off' an infinite alert, but still be able to read the error log.

   var logErrors= true, errorLog= [];
    function Yikes(str){
     if(str.constructor==Error)str=str.message;
     errorLog.push(str);
     if(logErrors== true){
      logErrors= confirm(str+'\n keep showing errors? ');
     }
     return true;
    }
    window.onerror=Yikes;

you can also use it around problem code, to return values:

  try{
   d2= Date.fromUTCArray(D.slice(0, D.length));
  }
  catch(er){
   return Yikes(er.message+', '+D);
  }
kennebec
  • 102,654
  • 32
  • 106
  • 127