Connecting Tech Pros Worldwide Forums | Help | Site Map

Writing Debug Messages to the Javascript Console

ion
Guest
 
Posts: n/a
#1: Jul 23 '05
Hi!
Is there a way to write messages to the javascript console? Like a
debug.write() method?
Thanks!
Ion


Nathan
Guest
 
Posts: n/a
#2: Jul 23 '05

re: Writing Debug Messages to the Javascript Console


if you're talking about the Mozilla/Firefox javascript console, there's
a pretty good wiki document over at mozillazine:

http://kb.mozillazine.org/JavaScript_Console

looks like the easiest way is to do it like this:

consoleService.logStringMessage("Hello world!");
[color=blue]
> Is there a way to write messages to the javascript console?[/color]

ion
Guest
 
Posts: n/a
#3: Jul 23 '05

re: Writing Debug Messages to the Javascript Console


Nathan,
Thanks. I couldn't get that to work. I get
Permission denied to get property UnnamedClass.classes
I think that service is intended for XUL applications. Is there no
way to write to it with JavaScript? There's a filter for 'messages
only' in the JavaScript Console itself, so it seems to want to be
written to.
Ion

ion
Guest
 
Posts: n/a
#4: Jul 23 '05

re: Writing Debug Messages to the Javascript Console


OK, Neil provides the answer in
http://groups-beta.google.com/group/...ef5e734f6f2123
var message = "Hello, world!";
setTimeout(message, 0);

since "Hello, world!" isn't resolvable as a method call, this gets
logged as an error [I get 'Missing ; before statement', but it would
probably be different for a single word message.]

Hallvord R. M. Steen
Guest
 
Posts: n/a
#5: Jul 23 '05

re: Writing Debug Messages to the Javascript Console


On Thu, 07 Apr 2005 20:02:37 +0200, ion <ionFreeman@gmail.com> wrote:
[color=blue]
> Is there a way to write messages to the javascript console? Like a
> debug.write() method?[/color]

You got an answer for Mozilla already :-)

If you debug your script in Opera you can use

opera.postError();

:-)
caston
Guest
 
Posts: n/a
#6: Jul 23 '05

re: Writing Debug Messages to the Javascript Console



ion wrote:[color=blue]
> Hi!
> Is there a way to write messages to the javascript console? Like a
> debug.write() method?
> Thanks!
> Ion[/color]

The best way to write to debug console is the follwoing:

throw new Error("An error occured bla-bla...")

Note, that using this construction will cause an error alert in IE
browser, and will write to javascript console in Mozilla-based
browsers.
In both cases the script flow will be interrupted after the error
arisen.

ion
Guest
 
Posts: n/a
#7: Jul 23 '05

re: Writing Debug Messages to the Javascript Console


caston,
Thanks! I don't want to leave the method body, is why I'm not
throwing errors.
Ion

ion
Guest
 
Posts: n/a
#8: Jul 23 '05

re: Writing Debug Messages to the Javascript Console


Dude! Opera rules! It's unfortunately not a supported platform for my
application. Tough to make the business case.
Thanks for your help!

Thomas 'PointedEars' Lahn
Guest
 
Posts: n/a
#9: Jul 23 '05

re: Writing Debug Messages to the Javascript Console


ion wrote:
[color=blue]
> Thanks! I don't want to leave the method body, is why I'm not
> throwing errors.[/color]

Theoretically, you could re-catch the exception thrown, see
the JavaScript 1.5 Guide and/or Reference for details.

<http://web.archive.org/devedge.netscape.com/central/javascript/>


PointedEars
ion
Guest
 
Posts: n/a
#10: Jul 23 '05

re: Writing Debug Messages to the Javascript Console


Thomas,
Thanks! If I caught the errors, they wouldn't be logged. The funny
thing about the 1.5 Guide's discussion of exception handling is that
they put a function 'logMyErrors' in the catch block, without giving an
implementation. All I want to do, of course, is log errors, so there
you are.
setTimeout is working great for me.
Ion
Thomas 'PointedEars' Lahn wrote:[color=blue]
> ion wrote:
>[color=green]
> > Thanks! I don't want to leave the method body, is why I'm not
> > throwing errors.[/color]
>
> Theoretically, you could re-catch the exception thrown, see
> the JavaScript 1.5 Guide and/or Reference for details.
>
> <http://web.archive.org/devedge.netscape.com/central/javascript/>
>
>
> PointedEars[/color]

ion
Guest
 
Posts: n/a
#11: Jul 23 '05

re: Writing Debug Messages to the Javascript Console


Thomas,
Thanks! If I caught the errors, they wouldn't be logged. The funny
thing about the 1.5 Guide's discussion of exception handling is that
they put a function 'logMyErrors' in the catch block, without giving an
implementation. All I want to do, of course, is log messages, so there
you are.
setTimeout is working great for me.
Ion
Thomas 'PointedEars' Lahn wrote:[color=blue]
> ion wrote:
>[color=green]
> > Thanks! I don't want to leave the method body, is why I'm not
> > throwing errors.[/color]
>
> Theoretically, you could re-catch the exception thrown, see
> the JavaScript 1.5 Guide and/or Reference for details.
>
> <http://web.archive.org/devedge.netscape.com/central/javascript/>
>
>
> PointedEars[/color]

Closed Thread