views:

150

answers:

5

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).

+2  A: 

This may help :)

Sarfraz
A: 

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
I was using the console from http://eloquentjavascript.net/.
Christy John
+1  A: 

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

Bialecki
A: 

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 ;)

Pablo Cabrera
yeah, the grant idea is o move to firebug. but before that I need to get a basic understanding of JavaScript first.
Christy John
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
A: 

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