How to use Document close in JavaScript
This article describe about Document close() Method in JavaScript.
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
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
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
Note: After click on the button new window open with this text.
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