Search w3schools.com:

SHARE THIS PAGE

Document close() Method

Document Object Reference Document Object

Definition and Usage

The close() method closes the output stream previously opened with the document.open() method, and displays the collected data in this process.

Syntax

document.close()


Browser Support

Internet Explorer Firefox Opera Google Chrome Safari

The close() method is supported in all major browsers.


Examples

Example 1

Open an output stream, add some text, then close the output stream:

<html>
<head>
<script>
function createDoc()
  {
  var doc=document.open("text/html","replace");
  var txt="<html><body>Learning about the HTML DOM is fun!</body></html>";
  doc.write(txt);
  doc.close();
  }
</script>
</head>

<body>
<input type="button" value="New document" onclick="createDoc()">
</body>
</html>

Try it yourself »

Example 2

Open an output stream (in a new window; about:blank), add some text, then close the output stream:

<html>
<body>

<script>
var w=window.open();
w.document.open();
w.document.write("<b>Hello World!</b>");
w.document.close();
</script>

</body>
</html>

Try it yourself »


Document Object Reference Document Object

Your suggestion:

Close [X]

Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]