Blog Stats
  • Posts - 8
  • Articles - 0
  • Comments - 4
  • Trackbacks - 0

 

Using javascript to Write to a New Child Window

I'm almost embarrassed to put this up because it's so small, but it's something I used to do all the time and had reason to have to re-learn it recently for something I was doing.

Sometimes -- at least until I find a better way -- I need to be able to get "editable" debugging text out of javascript.  Using the "alert" box doesn't work for this because you can't do the ctrl-c trick to get its text.  (For some message boxes, you can hit ctrl-c and it'll copy the contents such that you can put it into notepad.)

Anyway, the javascript below will cause a new window to open and will write whatever you want into it.  Then you can do whatever you would normally do with what shows up in IE windows.  FYI, the contents of the open() method is a double-apostrophe for a required parameter that nevertheless can be empty.

window.open('').document.write('your text here')

Print posted @ Tuesday, April 01, 2008 12:45 PM


Feedback

# re: Using javascript to Write to a New Child Window

Gravatar

If you develop in Firefox with Firebug, you can use console.log('Text') and it will output the text to the Firebug console. You could also use Sys.Debug.trace if you are using ASP.NET AJAX. This will use console.log if present, but it can also write to html elements if they are named properly and it can post back to the server to write in VS Output window if running in debug mode.

4/1/2008 2:44 PM | Shaun

# re: Using javascript to Write to a New Child Window

Gravatar

Along with what Shuan said; Nikhils web development helper also hooks into Sys.Debug.trace and will print out debug info in its' console. I use both FireBug and Nikhil's tool. They've saved my hair line many times over :D

4/2/2008 9:52 AM | Jim L.

# re: Using javascript to Write to a New Child Window

Gravatar

Another option is that if you are using the MS ASP.NET Ajax Client-Side library (AKA MS Ajax), you can use

Sys.Debug.trace("some text");

or

Sys.Debug.traceDump(someObject);

In Firefox, these print to FireFox JS log.  If you are in IE, you can put a textarea on the page called "tracelog" and the messages will appear here.  

The differences in the above calls is that "traceDump" actually dumps out the underlying values of the object, where "trace" prints a message.

4/2/2008 11:15 AM | jkimble

Post a comment





 

Please add 1 and 3 and type the answer here:

 

 

Copyright © Edward Buatois