JavaScript » Document » open

Syntax:
document.open([mimeType[, replace]])

This method is used to open a stream to collect the output from any write or writeln methods.

This method is used to open a stream to collect the output from any write or writeln methods. The first of the optional parameters is mimeType which determines the type of document you are writing to; if this parameter is not used, the default value is "text/html". The second parameter is replace, also optional, which causes the history entry for the new document to inherit the history entry from the document from which it was opened.

Examples

Code:
function newWindowTest() {
  var message1 = "Hello, world!"
  var message2 = "This is a test."
  newWindow.document.open("text/html", "replace")
  newWindow.document.writeln(message1)
  newWindow.document.write(message2)
  newWindow.document.close()
}

newWindow=window.open('','','toolbar=no,scrollbars=no,width=200,height=150')
newWindowTest()
Output:
"Hello, world! This is a test."
Explanation:

The following code demonstrates this method and displays the output stream in a new window.