开发者

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 norm开发者_JAVA百科al 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).


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


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


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


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜