Writing Content to a Window
The window.open() method opens a new window, while the document.open() method opens a document to collect the output of write() or writeln() methods. Its general syntax is:
oNewDoc = document.open(sMimeType[, sReplace]);
sMimeType is a string that specifies the MIME type. Navigator supports several different MIME types, but Internet Explorer currently only supports "text/html". The second argument is a string that specifies whether the new document being written is to replace the current document in the History list. Otherwise, by default, the document being created does not replace the current document in the History list. The sMimeType parameter is optional. If you want the new document to replace the current one in the History list, you should supply the string "replace".
"replace" is typically used on a window that has a blank document or an "about:blank" URL. After "replace" is specified, the write() method typically generates HTML for the window, replacing the history entry for the blank URL. Take care when using generated HTML on a window with a blank URL. If you do not specify "replace", the generated HTML has its own history entry, and the user can press the Back button and back up until the frame is empty.
Take a look at the following script segment:
var oNewDoc = document.open("text/html", "replace");
var sMarkup = "<HTML><HEAD><TITLE>New Document</TITLE></HEAD>";
sMarkup += "<BODY>Hello, world!<BR><A HREF='write.html'>Return</A></BODY></HTML>";
oNewDoc.write(sMarkup);
oNewDoc.close();
Click the following button to run this script:
";
sMarkup += "Hello, world! Return
|