Document. open () and document. write () _ basic knowledge

Source: Internet
Author: User
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.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.