Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Mail Systems
Eclipse Documentation

How To Guides
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Problem Solutions
Privacy Policy




The JavaScript FAQ
Prev Home Next

Writing to a window

Question: How do I write script-generated content to another window?

Answer: To write script-generated content to another window, use the method winRef.document.write() or winRef.document.writeln(), where winRef is the window reference, as returned by the method.

To make sure that your script's output actually shows up in the other window, use winRef.document.close() after writing the content. As an example, consider the following function that opens a new window with the title Console and writes the specified content to the new window.

writeConsole('Hello from JavaScript!');
function writeConsole(content) {'','myconsole',
   +'<body bgcolor=white onLoad="self.focus()">'
In the above example, you might notice that after you write something to the console several times, the console window will allow you to navigate back and forth in the output's history. This is not always a desired feature. If you would like to output the new content without creating a new history entry, add the following operator after opening the window (and before the first write):
docRef ="text/html","replace");
Here winRef is the window reference returned by the method, and docRef is a global variable in which the script stores the reference to your new document. Copyright © 1999-2006, Alexei Kourbatov

The JavaScript FAQ
Prev Home Next

  Mirrored with kind permission of Alexei Kourbatov Design by Interspire