Chris said:[color=blue]
>
>Can anyone point me to some code that will display messages, in a seperate
>window, from javascipt. ie effectively a trace window?[/color]
In article <PTtVc.475$Nq1. 340@newsfe6-gui.ntli.net>, "Chris" <.@>
wrote:
[color=blue]
> Can anyone point me to some code that will display messages, in a seperate
> window, from javascipt. ie effectively a trace window?
>[/color]
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>javascri pt debug routines and tester</title>
<script type="text/javascript">
function startDebug(debu gMode) {
startDebug.debu gMode = debugMode;
if (startDebug.deb ugMode == true) {
var debugWindowName =
document.URL.su bstr(document.U RL.lastIndexOf( "/")+1);
var thePosition = debugWindowName .indexOf(".");
if (thePosition > 0)
{ debugWindowName = debugWindowName .substr(0,thePo sition); }
startDebug.newW indow = window.open("", debugWindowName ,
"scrollbars=yes ,resizable=yes, width=700,heigh t=500");
startDebug.newW indow.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,'docum ent');
function dumpProperties( obj, obj_name)
{
var i;
// Example invocation & print: DumpProperties( document,'docum ent');
if (startDebug.deb ugMode == true )
{
debugOut('In DumpProperties. obj=' + obj_name);
for (i in obj)
{
try
{
debugOut(obj_na me + "." + i + " = " + obj[i]);
}
catch(e)
{
debugOut("Error writing out structure. Was " + e + " for " + i);
}
}
}
}
function dumpPropertiesS orted(obj, obj_name)
{
var i;
var sorted = [ ];
var objCount = 0;
for ( i=0; i <sorted.lengt h; i++)
{
try
{
debugOut(obj_na me + "." + sorted[i] + " = " +
obj[sorted[i]]);
}
catch(e)
{
debugOut("Error writing out structure. Was " +
i + " for " + sorted[i]);
}
}
} // if we are debugging.
}
function debugOut(obj)
{
var theString = "" + obj;
if (startDebug.deb ugMode == true ) {
// Ordering of the replacement string is important
var theString = theString.repla ce(
/&/g, "&").replac e(
/</g, "<").replace (
/>/g, ">");
// theString = theString.repla ce(/ /g, " ");
startDebug.newW indow.document. writeln(theStri ng + "<br>");
}
}
</SCRIPT>
</head>
<body>
<script>
var test = {a:1, c:3, b:2};
var testBoolean = true;
startDebug(true );
dumpProperties( test,"test");
debugOut("displ ay the test object in sorted form");
dumpPropertiesS orted(test,"tes t");
debugOut(testBo olean);
debugOut("<b>&< \/b>");
</script>
<p>Debug routines and testing.</p>
</body>
</html>
"Chris" <.@> wrote in message news:<fmFVc.364 $tc5.68@newsfe6-gui.ntli.net>.. .[color=blue]
> Thanks v much, works a treat[/color]
Glad to have helped out.
[color=blue]
>
> one oddity though[/color]
;-)
[color=blue]
> in IE 6 I had to alter the following
>[/color]
[color=blue]
> Error: Invalid argument.
> ---------------------------[/color]
I suspect you had a special character in your file name. I am using
the filename as the debug window name. Web browsers seem to take the
input file name and use the escape function on them. For instance,
the space character in a file name is converted to %20. The IE
version of window.opend doesn't accept a % as part of the debug window
name.
I have posted a new version of the file below. I filter out the % and
all the other special characters.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>javascri pt debug routines and tester</title>
<script type="text/javascript">
// Popup the debug window.
// You need to have enabled popup windows
function startDebug(debu gMode) {
startDebug.debu gMode = debugMode;
if (startDebug.deb ugMode == true) {
var debugWindowName =
document.URL.su bstr(document.U RL.lastIndexOf( "/")+1);
var thePosition = debugWindowName .indexOf(".");
if (thePosition > 0)
{ debugWindowName = debugWindowName .substr(0,thePo sition); }
// Get rid of special characters because IE won't accept them
for ( i=0; i <sorted.lengt h; i++)
{
try
{ debugOut(obj_na me + "." + sorted[i] + " = " +
obj[sorted[i]]); }
catch(e)
{ debugOut("Error writing out structure. Was " +
i + " for " + sorted[i]); }
}
} // if we are debugging.
}
function debugOut(obj)
{
var theString = "" + obj;
if (startDebug.deb ugMode == true ) {
// Ordering of the replacement string is important
var theString = theString.repla ce(
/&/g, "&").replac e(
/</g, "<").replace (
/>/g, ">");
// theString = theString.repla ce(/ /g, " ");
startDebug.newW indow.document. writeln(theStri ng + "<br>");
}
}
</SCRIPT>
</head>
<body>
<script>
var test = {a:1, c:3, b:2};
var testBoolean = true;
startDebug(true );
dumpProperties( test,"test");
debugOut("displ ay the test object in sorted form");
dumpPropertiesS orted(test,"tes t");
debugOut(testBo olean);
debugOut("<b>&< \/b>");
Comment