如何调试javascript? [英] How to debug javascript?

查看:124
本文介绍了如何调试javascript?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在2000-2002年期间有一些旧的JavaScript代码(令人惊讶的是)仍然可以在IE中使用,但不能在Firefox,Chrome,Opera等等。我已经发现了一些怪癖,一些浏览器会这样做一些事情,另一个。因此,互联网上有代码片段来创建一些独立于浏览器平台的功能。



现在我的问题是,甚至找到问题。现在,网站上有按钮,当我点击它们时,在IE中发生了一些事情,但Firefox完全没有。甚至没有错误。我试图通过JavaScript Firebug,但在代码的某个时候,当我做下一个调试步骤时,脚本似乎中止,没有任何错误消息。它不会继续下一个语句。很奇怪,我不知道是什么原因或如何解决它。 :/



那么如何调试javascript,所以我得到错误消息告诉我什么是问题,例如,我使用的是什么函数/变量没有定义在firefox或当我使用错误的参数。



Thx&最好的问候
Marc

解决方案

Firefox不会弹出错误消息或将它们放在状态栏(如IE) 。您必须打开错误控制台才能看到错误。



Firefox将错误控制台中的Javascript错误,还包括HTML和CSS错误和警告。



对于代码中可能无法使用的内容,有很多特定的东西是IE特定的,不能在任何其他浏览器中运行。另外IE还有一个很大的区别,IE在怪异模式和IE在标准兼容模式。在页面中放置一个适当的doctype,使其以标准兼容模式呈现,这将使IE更像其他浏览器,并且某些IE特定的怪癖被删除。这可能会导致您的旧脚本停止工作,在这种情况下,您可能知道这是一些特定于IE的功能,导致该问题。


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

解决方案

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.

这篇关于如何调试javascript?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆