HTML DOM Document close() method
- Previous page characterSet
- Next page cookie
- Return to the previous level HTML DOM Documents
Definition and usage
close()
The method closes the window previously opened with the open() method.
Note:The document.open() method clears the document (overwriting all previous content).
See also:
Related pages
Example
Example 1
Open a document, write some text into it, and then close it:
document.open(); document.write("<h1>Hello World</h1>"); document.write("<p>Open owerwrites original content.</p>"); document.close();
Example 2
Open a new window, then open a document, write some text into it, and then close it:
const myWindow = window.open(); myWindow.document.open(); myWindow.document.write("<h1>Hello World!</h1>"); myWindow.document.close();
Syntax
document.close()
Parameter
None.
Return value
None.
Browser support
document.close()
It is a feature of DOM Level 1 (1998).
All browsers support it:
Chrome | IE | Edge | Firefox | Safari | Opera |
---|---|---|---|---|---|
Chrome | IE | Edge | Firefox | Safari | Opera |
Support | 9-11 | Support | Support | Support | Support |
- Previous page characterSet
- Next page cookie
- Return to the previous level HTML DOM Documents