W3Schools.com

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 type="text/javascript">
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 type="text/javascript">
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
WEB HOSTING
Best Web Hosting
PHP MySQL Hosting
Best Hosting Coupons
UK Reseller Hosting
Cloud Hosting
Top Web Hosting
$7.95/mo SEO Hosting
Premium Website Design
WEB BUILDING
Download XML Editor
FREE Website BUILDER
Free Website Templates Free CSS Templates
Make Your Own Website
W3SCHOOLS EXAMS
Get Certified in:
HTML, CSS, JavaScript, XML, PHP, and ASP
W3SCHOOLS BOOKS
New Books:
HTML, CSS
JavaScript, and Ajax
STATISTICS
Browser Statistics
Browser OS
Browser Display
SHARE THIS PAGE