473,385 Members | 1,429 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

javascript trace window

Can anyone point me to some code that will display messages, in a seperate
window, from javascipt. ie effectively a trace window?
TIA

Chris
Jul 23 '05 #1
6 6039
Lee
Chris said:

Can anyone point me to some code that will display messages, in a seperate
window, from javascipt. ie effectively a trace window?


alert(msg);

Jul 23 '05 #2
In article <PT***************@newsfe6-gui.ntli.net>, "Chris" <.@>
wrote:
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[i]);
}
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[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.debugMode == true ) {
// Ordering of the replacement string is important
var theString = theString.replace(
/&/g, "&amp;").replace(
/</g, "&lt;").replace(
/>/g, "&gt;");
// theString = theString.replace(/ /g, "&nbsp;");
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>
Jul 23 '05 #3
Thanks v much, works a treat

one oddity though
in Opera 7.51 all OK
in IE 6 I had to alter the following

//startDebug.newWindow = window.open("",debugWindowName,
"scrollbars=yes,resizable=yes,width=700,height=500 ");
startDebug.newWindow = window.open("",null,
"scrollbars=yes,resizable=yes,width=700,height=500 ");

as it was throwing the following error

---------------------------
Error
---------------------------
A Runtime Error has occurred.
Do you wish to Debug?

Line: 15
Error: Invalid argument.
---------------------------
Yes No
---------------------------

Again my thanks

Chris
"Robert" <rc*******@my-deja.com> wrote in message
news:rc*****************************@news6.west.ea rthlink.net...
In article <PT***************@newsfe6-gui.ntli.net>, "Chris" <.@>
wrote:
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[i]);
}
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[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.debugMode == true ) {
// Ordering of the replacement string is important
var theString = theString.replace(
/&/g, "&amp;").replace(
/</g, "&lt;").replace(
/>/g, "&gt;");
// theString = theString.replace(/ /g, "&nbsp;");
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>

Jul 23 '05 #4
"Chris" <.@> wrote in message news:<fm**************@newsfe6-gui.ntli.net>...
Thanks v much, works a treat
Glad to have helped out.

one oddity though
;-)
in IE 6 I had to alter the following
Error: Invalid argument.
---------------------------


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>javascript debug routines and tester</title>

<script type="text/javascript">

// Popup the debug window.
// You need to have enabled popup windows

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); }
// Get rid of special characters because IE won't accept them

debugWindowName =
debugWindowName.match(/[a-zA-Z0-9]/g).join("");

try
{ startDebug.newWindow = window.open("",debugWindowName,
"scrollbars=yes,resizable=yes,width=700,height=500 "); }
catch(e)
{ debugWindowName = "debug";
startDebug.newWindow = window.open("",debugWindowName); }

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)
{
//Example invocation & print: DumpProperties(document,'document');
if (startDebug.debugMode == true )
{
debugOut('In DumpProperties. obj=' + obj_name);
for (var i in obj)
{
try
{ debugOut(obj_name + "." + i + " = " + obj[i]); }
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[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.debugMode == true ) {
// Ordering of the replacement string is important
var theString = theString.replace(
/&/g, "&amp;").replace(
/</g, "&lt;").replace(
/>/g, "&gt;");
// theString = theString.replace(/ /g, "&nbsp;");
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>");

var myString = "abcDEF Ghi~123~ *&^ end";
debugOut("myString = " + myString +
" compressed: " +
escape(myString.match(/[a-zA-Z0-9]/g).join("") ) );

</script>
<p>Debug routines and testing.</p>
</body>
</html>
Jul 23 '05 #5
Lee
Robert said:
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>");


Opening and then writing into a window is unreliable.
It's much safer to have the new window load the content when it's ready.

function log(msg) {
globalHTML="<html><body><p>"+msg+"</p></body></html>";
window.open("javascript:opener.globalHTML",
"logWindow",
"width=400,height=200,resizable").focus();
}

Since the window opens immediately, there's really no point in displaying the
date.

Jul 23 '05 #6
Tom
How can you get this to autoscroll to the trace line just entered?
Jul 23 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Java script Dude | last post by:
I have still yet to see a JavaScript Editor that comes close to reading a good JS book, learing it and using it with a text editor. Anyway, here my recipe for build successfull DHTML...
9
by: Artist | last post by:
Mozilla and IE works different with Javascript. I have Javascript Code which works fine with Mozilla and it breaks with Internet Explorer. I like to convert my code to work with both the...
14
by: tshad | last post by:
I posted this on the asp.net group, also. I wasn't sure whether this was an asp.net problem or a javascript problem. I have a page that was originally created from a program I found on the net...
5
by: martin | last post by:
Hi, The trace class seems to me to be very usefull however there are a few features of it that have to confused. I am using visual studio 2003. the IDE will not let me write ...
9
by: tshad | last post by:
This is from my previous post, but a different issue. I have the following Javascript routine that opens a popup page, but doesn't seem to work if called from an asp.net button. It seems to work...
3
by: mikeorb | last post by:
I'm debugging some JavaScript. In Firefox I can use dump(msg) to print a message on their JS console (see http://kb.mozillazine.org/Viewing_dump()_output). Likewise, Opera has the...
2
by: OTSolutions | last post by:
This line of code works in IE but not in Firefox or Netscape for some reason. Any ideas as to why would be appreciated, It is the NavigateURL part. IE brings up the page, the other two...
3
by: Arman Sahakyan | last post by:
Hi, I'm an MFC programmer and know little about .NET programming. Now, for some reasons, I'm developing an ASP .NET application... What I need to know is how to output into VS's Output Window...
2
by: joelkeepup | last post by:
Hi, I made a change this morning and now im getting an error that says either "a is undefined or null" or "e is undefined or null" the microsoft ajax line is below, I have no idea how to...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.