开发者

How to debug javascript? [duplicate]

This question already has answers here: How can I debug my JavaScript code? [closed] (20 answers) Closed 6 years ago.

I have some old javascript code from around 2000-2002 which (surprisingly) still works in IE, but doesn't in Firefox, Chrome, Opera etc. I already found out about some quirks, some browsers do some things 开发者_JAVA技巧this way, some another. So there are code snippets on the internet to create some browser plattform independent function that does it.

Now my problem is, to even locate the problems. Right now, there are buttons in the website, when I click them, something happens in IE, but Firefox does just nothing. There isn't even an errormsg. I tried stepping through the javascript Firebug, but at some point in the code, when I do the next debug step, the script just seems to abort, without any error message. It doesn't continue with the next statement. Pretty strange and I have no idea what causes it or how to fix it. :/

So how do I debug javascript so I get error messages telling me what the problem is, for example, what function/variable I'm using isn't defined in firefox or when I use wrong parameters.

Thx & Best regards Marc


Firebug for firefox is okay. The console for safari and chrome, IMO, is better. In either case, right click the page, hit "inspect element," and click the "console" tab in the pane that pops up. Now you'll see any errors and warnings generated by the page.

If you really want to debug the scripts you can click on the "Scripts" tab and either pause execution immediately or set a break point. Then, you can step through the execution of the script line by line, inspecting the call stack and watch list as you go.


Firefox doesn't popup error messages or put them in the status bar (like IE). You have to open the Error Console to see the errors.

Firefox puts Javascript errors in the Error Console, but also HTML and CSS errors and warnings.

As to what might not work in the code, there are plenty of things that are IE specific and won't work in any other browser. Also there is a big difference between IE in quirks mode and IE in standards compliant mode. Put a proper doctype in the page so that it's rendered in standards compliant mode, which will make IE more like other browsers, and some IE-specific quirks are removed. This might cause your old script to stop working, in which case you know that it's likely that it's some IE-specific feature that causes the problem.


There's FireBug, but it only works for Firefox.

EDIT: Doh, you already mentioned this in your question.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜