Christy John
Christy John

Reputation: 680

Stopping infinite loops of alerts in Mozilla

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

Upvotes: 3

Views: 1320

Answers (4)

kennebec
kennebec

Reputation: 104780

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

Upvotes: 0

Pablo Cabrera
Pablo Cabrera

Reputation: 5849

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

Upvotes: 0

Bialecki
Bialecki

Reputation: 31051

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

Upvotes: 1

Shaunwithanau
Shaunwithanau

Reputation: 585

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

Upvotes: 0

Related Questions