How to use Document close in JavaScript

This article describe about Document close() Method in JavaScript.
  • 1850

Document close() Method

This method is used to close the output which previously opened with the document.open() method, and show the gather data in this process.

Syntax

document.close()

 

Example

 

<!DOCTYPE html>

<html>

<head>

<script type="text/javascript">

function createDocument()

  {

  var doc=document.open("text/html","replace");

  var txt="<!DOCTYPE html>

<html><body>Learning about the HTML DOM is very interesting!</body></html>";

  doc.write(txt);

  doc.close();

  }

</script>

</head>

<body>

<input type="button" value="New doc" onclick="createDocument()" />

</body>

</html>

Output

pi c12.jpg

Example 2.

<!DOCTYPE html>

<html>

<head>

<script type="text/javascript">

    function createDocument() {

        var win = window.open();

        win.document.open();

        win.document.write("<h1>Welcome in new window!</h1>");

        win.document.close();

    }

</script>

</head>

<body>

<input type="button" value="New document in a new window" onclick="createDocument()" />

</body>

</html>

 

Output


pic13.jpg 

 

Note: After click on the button new window open with this text.

 

pic14.jpg

You may also want to read these related articles Click here

Ask Your Question 

Got a programming related question? You may want to post your question here

Programming Answers here

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.