Home > Web Front-end > JS Tutorial > body text

The difference between document.open() and document.write()_javascript skills

WBOY
Release: 2016-05-16 19:10:14
Original
986 people have browsed it

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>

Related labels:
and
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template