HTML DOM Document close()

Example

Open a document, write some text to it, and close it:

document.open();
document.write("<h1>Hello World</h1>");
document.write("<p>Open owerwrites original content.</p>");
document.close();
Try it Yourself »

Open a new window, then open a document, write some text to it, and close it:

const myWindow = window.open();
myWindow.document.open();
myWindow.document.write("<h1>Hello World!</h1>");
myWindow.document.close();
Try it Yourself »

Description

The close() method closes a window previously opened with the open() method.

Warning

The document.open() method clears the document (overwrites all previous content).



Syntax

document.close()

Parameters

NONE

Return Value

NONE

Browser Support

document.close() 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


Copyright 1999-2023 by Refsnes Data. All Rights Reserved.