Home >Web Front-end >JS Tutorial >The difference between document.open() and document.write()_javascript skills
document.open() opens a new blank document. Under 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 new document will overwrite the document of the current page (equivalent to clearing all elements in the original document, and cannot go back, that is, the browser's back button is unavailable);
Look at an example :
Usually do not write document.open() and document.close() because the browser will open a document before writing. Then output the content of write to the original document. After the write is completed, there will be no close by default, otherwise the second line of document.write will overwrite the previous write. <script> <BR><!-- <BR>function test(){ <BR> document.open("text/html","replace"); <BR> document.writeln(Math.random()); <BR> document.write("<input type='button' value='back(第二个按钮)' onclick='history.back()'>") <BR> document.close(); <BR> document.open("text/html",""); <BR> document.writeln(Math.random()); <BR> document.write("<input type='button' value='back(第三个按钮)' onclick='history.back()'>") <BR> document.close(); <BR> document.open("text/html",""); <BR> document.writeln(Math.random()); <BR> document.write("<input type='button' value='back(第四个按钮)' onclick='history.back()'>") <BR> document.close(); <BR>} <BR>//--> <BR></script>