HTML DOM Document close() method

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:

Document open() method

Window open() Method

Window close() Method

Related pages

Document write() method

Document writeln() method

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();

Try it yourself

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();

Try it yourself

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