Open this document, write some text, and close:
document.open();
document.write("<h1>Hello World</h1>");
document.close();
Try it Yourself »
Using document.open() in a new window:
const myWindow = window.open();
myWindow.document.open();
myWindow.document.write("<h1>Hello World!</h1>");
myWindow.document.close();
Try it Yourself »
More examples below.
The open()
method opens a document for writing.
All existing document content will be cleared.
Do not confuse this method with the window.open() method, which opens a new browser window.
document.open()
document.open(Mimetype, replace)
Parameter | Description |
Mimetype | Ignored by all modern browsers. |
replace | Ignored by all modern browsers. |
NONE |
If document.write() is used on a closed document, document.open() is automatically called. This will delete existing content.
document.write("<h1>Hello World!</h1>");
Try it Yourself »
document.Open()
is a DOM Level 1 (1998) feature.
It is fully supported in all browsers:
Chrome | Edge | Firefox | Safari | Opera | IE |
Yes | Yes | Yes | Yes | Yes | 9-11 |
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!