Document. open () and document. write () document. open () opens a new blank document. In IE, open has two default parameters, which are equivalent to document. open ("text/html", '""). The second parameter has only one optional value: replace. If this value is enabled, the newly created document will overwrite the document on the current page (equivalent to clearing all elements in the original document, and the browser's back button is unavailable );
Let's look at an example:
<Script language = "JavaScript"> <! -- Function test () {document. open ("text/html", "replace"); document. writeln (Math. random (); document. write ("<input type = 'button 'value = 'back (second button) 'onclick = 'History. back () '> ") document. close (); document. open ("text/html", ""); document. writeln (Math. random (); document. write ("<input type = 'button 'value = 'back (third button) 'onclick = 'History. back () '> ") document. close (); document. open ("text/html", ""); document. writeln (Math. random (); document. write ("<input type = 'button 'value = 'back (fourth button) 'onclick = 'History. back () '> ") document. close () ;}// --> SCRIPT <input type = "button" value = "first button" onclick = "test ()">
[Ctrl + A select all Note: If you need to introduce external Js, You need to refresh it to execute]
Generally, document. open () and document. close () are not written, because the browser will open a document before writing, and then output the write content to the original document. After the write operation is complete, no close is performed by default. Otherwise, the previous write will be overwritten in the second line of document. write.