开发者

Turning on error reporting for a JavaScript segment?

I haven't worked in JS since 1999, so I'm quite rusty. I remember working in it in the past, and I was able to enable some kind of error reporting. Right now, 开发者_如何学编程when I have a syntax error in a script, no error is reported in the browser. Is there a directive or something to enable error reporting in a JS file?


Most scripts in the wild are so full of crass errors that browsers don't bother complain about them any more.

In IE by default the error indicator in the left hand side of the status bar can be used to display the error. Or you can turn error alerts back on from Internet Options -> Advanced -> Browsing -> Display a notification about every script error, but that will make the rest of the internet unusably annoying.

In Firefox, Tools -> Error Console will bring back the familiar JavaScript console.


It's impossible to over-recommend the Firebug plugin for Firefox. It's become the de-facto standard for writing and debugging javascript. In the console panel of firebug, you'll find lots of errors and warnings you can toggle. In addition it allows inspecting dom elements, watching network timing, ajax calls, modifying html/css/and even adding code to live pages, in addition to a plugin system which allows a host of third-party utilities built on Firebug.


Browsers generally report errors in a non obtrusive way (probably because first JavaScript code written by amateurs was very buggy, plus end users (besides devs) don't know what to do with an error anyway).

Firebug for Firefox is great, and so is Web Inspector for Webkit. They both have a console you can print to using something like

console.log(str);
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜