How to use Document open in JavaScript
This article describe about Document open() Method in JavaScript.
Document open() Method
From document.write() or document.writeln() methods collect the output which are used to open() method to opens an output stream.
If all writing action performed, then document.close() method causes and output written to the output stream display.
Note: It will be cleared> If document already exists in the target, and method has no argument then new window (aboutblank) is displayed.
Syntax
document.open(MIMEtype,replace)
|
Parameter |
Description |
MIMEtype |
Optional. Type of document that are writing to. |
replace |
Optional. If set, the history entry for new inherited document to the document open. |
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 output become.
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