Javascript DOM HTML document open() Method

Introduction

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

Click the button to open an output stream, add some text, and close the output stream.

View in separate window

<!DOCTYPE html>
<html>
<body>
<button onclick="myFunction()">Test</button>

<script>
function myFunction() {/* ww w  .j  a  v  a 2  s . c  om*/
  document.open();
  document.write("<h1>Hello World</h1>");
  document.close();
}
</script>

</body>
</html>

The open() method opens an output stream to collect the output from any document.write() or document.writeln() methods.

If a document already exists in the target, it will be cleared.

document.open([MIMEtype,][replace]);

Parameter Values

Parameter Description
MIMEtype Optional. Default value is "text/html"
replace Optional. the history entry for the new document inherits the history entry from the document which opened this document

The open() method returns no value.




PreviousNext

Related