|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
|
Announcements
Chapters
Services
Feature Zones
|
DisclaimerThe author does not accept responsibility for any effects, adverse or otherwise, that this code may have on you, your computer, your sanity, your dog, and anything else that you can think of. Use it at your own risk. (Deja Vu? I also love the Allegro disclaimer.) Quick and dirty tourSo you don't like to read all articles you see on the web, or you don't have time for it? Then, just download the source files, and open the "debugDemo.htm" file on your favorite browser. BackgroundAlthough the inner works require you to be an advanced web developer to understand and improve it, you need only to have basic knowledge of HTML and JavaScript to use the tool. IntroductionAlright, you may be thinking right now: "I have the last Fire Bug extension for FireFox, I've got my WebDev bar for Fire Fox and Internet Explorer, and even Opera has a concrete JavaScript console. Why would I care about a tool for JavaScript debugging?". Well, please, let me try to convince you! The need for a debug toolAlthough browsers have their JavaScript console, it's mostly common to see people still use those famous The debug toolThe debug tool is composed of a js file (and an internal css file), which must be included on your HTML page, as shown in the example below: <html>
<head>
<title>Debug Demo</title>
<script type="text/javascript" src="DebugHelper.js"></script>
...
</head>
When you run the debug tool by opening its window, you will see a floating popup like the image in the top of this article, where your will find all information you send to one of these class methods: //debug helper class to control popup windows
var DebugHelper = function()
{
this.Active = true;
this.OpenWindowOnFirstMessage = true;
this.ShowCallee = true;
this.ShowInputArguments = true;
this.ShowCaller = true; // may not work on all browsers, since it is
// deprecated
this.ShowCallStack = true; // may work on few browsers [Gecko], since
// it is not a W3C recommendation
this.ShowException = true;
this.ShowURL = true;
this.ShowLastModified = true;
this.ShowReferrer = true;
this.VerboseMode = false;
//reference to the popup window
this.DebugWindow = null;
this.CssStyleFile = new String("debugHelper.css");
this.WindowStyle = new String("left=0,top=0,width=300,height=300," +
"scrollbars=yes,status=no,resizable=yes");
//no spaces to run correctly on internet explorer
this.WindowName = new String("JavascriptDebugWindow");
this.WindowTitle = new String("Javascript Debug Window");
}
Although the debug tool has so many configurations, you don't usually need to change it as the default values will suffice. Using the debug toolAs a code is worth thousand article words, let's start with it: <body>
<button onclick="ShowMe('showWindow');">Show the debug window</button>
<button onclick="ShowMe('message');">Show me a message</button>
<button onclick="ShowMe('warn');">Show me a warning</button>
<button onclick="ShowMe('exception');">Show me a exception</button>
<button onclick="ShowMe('throwError');">Throw a Error()</button>
<button onclick="ShowMe('hideWindow');">Hide the debug window</button>
<script type="text/javascript">
function ShowMe(type)
{
try
{
switch(type)
{
case "showWindow":
debugHelper.ShowWindow();
break;
case "hideWindow":
debugHelper.HideWindow();
break;
case "message":
debugHelper.Message("message");
break;
case "warn":
debugHelper.Warn("warn");
break;
case "exception":
debugHelper.Exception("exception");
break;
case "throwError":
throw Error("throwing error");
break;
}
}
catch(ex)
{
debugHelper.Exception(ex, document.URL, document.lastModified,
document.referrer, arguments);
}
}
</script>
...
</body>
Our demo page is a straightforward read, where you must mind some good coding practices. The function function NameOfYorFunction(anyParameters)
{
try
{
//your code here
}
catch(ex)
{
debugHelper.Exception(ex, document.URL, document.lastModified,
document.referrer, arguments);
}
}
Keeping your code under a My code is already deployed, can this debug tool help me?Although I cannot see all possible situations you may use this code in, my common answer is yes, it may be. If you add What about security?If you are thinking that anyone could activate debugging on your system, yes, you are right. This debugging technique is not for use with sensitive or private data. Although JavaScript is not indented to hold any type of sensitive data at all, it is always worthy to give that tip. ConclusionAnd that’s it for the JavaScript debugging tool! I hope you enjoy it as much as I do. ReferencesSome great resources on the web:
History
|
||||||||||||||||||||||