"Chris" <.@> said:
Can anyone point me to some code that will display messages, in a seperate
window, from javascipt. ie effectively a trace window?
This should help. Just run the file. The function debugOut displays a
message in the popup window created by startDebug. Be sure to enable
popup windows. My favorite line is:
debugOut("myVar = " + myVar);
alert is a point because you have to press enter and you loss was was
displayed.
Robert
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>javascript debug routines and tester</title>
<script type="text/javascript">
function startDebug(debugMode) {
startDebug.debugMode = debugMode;
if (startDebug.debugMode == true) {
var debugWindowName =
document.URL.substr(document.URL.lastIndexOf("/")+1);
var thePosition = debugWindowName.indexOf(".");
if (thePosition > 0)
{ debugWindowName = debugWindowName.substr(0,thePosition); }
startDebug.newWindow = window.open("",debugWindowName,
"scrollbars=yes,resizable=yes,width=700,height=500");
startDebug.newWindow.document.writeln(
'<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional' +
'//EN">' + "<html><header><title>Window " + debugWindowName +
"</title></header><body><p>The debug information " +
"that follows was generated on " + Date() + "</p>");
}
}
// Example invocation & print: DumpProperties(document,'document');
function dumpProperties(obj, obj_name)
{
var i;
// Example invocation & print: DumpProperties(document,'document');
if (startDebug.debugMode == true )
{
debugOut('In DumpProperties. obj=' + obj_name);
for (i in obj)
{
try
{
debugOut(obj_name + "." + i + " = " + obj
);
}
catch(e)
{
debugOut("Error writing out structure. Was " + e + " for " + i);
}
}
}
}
function dumpPropertiesSorted(obj, obj_name)
{
var i;
var sorted = [ ];
var objCount = 0;
if (startDebug.debugMode == true )
{
debugOut('In DumpProperties. obj=' + obj_name);
for (i in obj)
{
sorted[objCount++] = i;
}
sorted.sort();
for ( i=0; i <sorted.length; i++)
{
try
{
debugOut(obj_name + "." + sorted + " = " +
obj[sorted]);
}
catch(e)
{
debugOut("Error writing out structure. Was " +
i + " for " + sorted);
}
}
} // if we are debugging.
}
function debugOut(obj)
{
var theString = "" + obj;
if (startDebug.debugMode == true ) {
// Ordering of the replacement string is important
var theString = theString.replace(
/&/g, "&").replace(
/</g, "<").replace(
/>/g, ">");
// theString = theString.replace(/ /g, " ");
startDebug.newWindow.document.writeln(theString + "<br>");
}
}
</SCRIPT>
</head>
<body>
<script>
var test = {a:1, c:3, b:2};
var testBoolean = true;
startDebug(true);
dumpProperties(test,"test");
debugOut("display the test object in sorted form");
dumpPropertiesSorted(test,"test");
debugOut(testBoolean);
debugOut("<b>&<\/b>");
</script>
<p>Debug routines and testing.</p>
</body>
</html>