/

HTML / CSS / JavaScript Tutorial

JavaScript Document own method: open()

[this page | pdf | back links]

The open() method (when applied to the document object of the JavaScript DOM) opens an HTML output stream (into which output from write() or writeln() can go).

 

It has the following syntax with the following parameters. It does not return any value.

 

document.open(MIMEtype, replace)

 

Parameter

Required / Optional

Description

MIMEtype

Optional

The MIME type of the document being written to (default is "text/html".

replace

Optional

If set (i.e. present) then the history entry for the new document inherits the one for the document which opened it

 

Once all writes to the document have taken place, the document.close() method causes any output to be displayed. If a document already exists in the target then it will be cleared.

 

EXAMPLE:


HTML USED IN THIS EXAMPLE:
<!DOCTYPE html>
<html> <!-- Copyright (c) Nematrian Limited 2018 -->
<head>
<style>
table,td,tr,th,caption {border: thin solid black; border-collapse: collapse;}
</style>
</head>
<body>
Click anywhere on the document to open a new document<br><br>
<table >
  <tr><th>Dom method</th><th>Value returned</th></tr>
  <tr><td>Open</td><td id="x1"></td></tr>
</table>

<script>
document.addEventListener("click", addevent, false)

function addevent() {
  document.open()
}
</script>

</body>
</html>

FUNCTION THAT MAY ASSIST IN TESTING WHETHER FEATURE IS SUPPORTED:
function isSupportedJavaScriptMethodDomOpen() {
  return !!document.open;
}


NAVIGATION LINKS
Contents | Prev | Next | JavaScript DOM (and BOM)


Desktop view | Switch to Mobile