View Full Version : JavaScript error reporting
enuenu
10-13-2007, 11:44 PM
Is there any tool that will give an indication of errors in JavaScript coding? I have done some C++ programming in the past and when you try and compile C++ code that contains an error you at least get some indication of where the error is and what type of error it is. When I insert JavaScript into HTML pages I find that the script just won't work if it contains an error and I am left with no idea where or what the error is.
BillyGalbreath
10-14-2007, 12:28 AM
Firefox has a built in Error Console (http://zenit.senecac.on.ca/wiki/imgs/thumb/602px-Extension05.png). This can be found by clicking Tools, then Error Console from the Firefox menu. Firefox reports errors, warnings, and messages. Firefox's Error Console has also been known to output CSS errors and warnings as well as JavaScript.
Internet Explorer also outputs errors (http://devedge-temp.mozilla.org/viewsource/2003/mozilla-webdev/mozdev01.png), although it's not as powerful as Firefox's. This can be found when a page contains an error as a little yellow icon at the bottom left of the window in the status bar. Double click it to reveal the error message. Internet Explorer only reports errors, not warnings or messages. CSS errors are not included in this feature of Internet Explorer.
;)
enuenu
10-14-2007, 06:09 AM
Thanks a lot.
coothead
10-14-2007, 06:33 AM
Hi there enuenu,
Microsoft do have a downloadable script debugger which does give a little more information than the dialog box...
http://www.microsoft.com/downloads/details.aspx?FamilyID=2f465be0-94fd-4569-b3c4-dffdf19ccd99&displaylang=en
diades
10-14-2007, 06:54 AM
Hi
If you just want to see what and where then this simple script works in both IE and FF:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<meta name="description" content="" />
<meta name="keywords" content="" />
<meta name="author" content="" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<script type="text/javascript">
//<![CDATA[
window.onerror=fnErrorTrap;
function fnErrorTrap(sMsg,sUrl,sLine)
{
var oErrorLog = document.getElementById("oErrLog");
with(oErrorLog)
{
innerHTML="<b>An error was thrown and caught.</b><p>";
innerHTML+="Error: " + sMsg + "<br>";
innerHTML+="Line: " + sLine + "<br>";
innerHTML+="URL: " + sUrl + "<br>";
}
return false;
}
function fnThrow(oEl){
eval(oEl.value);
}
//]]>
</script>
<style type="text/css">
/*<![CDATA[*/
/*]]>*/
</style>
</head>
<body>
<form action="jvascript:void(0)">
<input type="text" id="oErrorCode" value="someObject.someProperty=true;" name="oErrorCode" />
<input type="button" value="Throw Error" onclick="fnThrow(oErrorCode)" />
</form>
<p>
<div id="oErrLog"></div>
</body>
</html>
vBulletin® v3.6.7, Copyright ©2000-2009, Jelsoft Enterprises Ltd.