/

HTML / CSS / JavaScript Tutorial

JavaScript Document own method: close()

[this page | pdf | back links]

The close() method (when applied to the document object of the JavaScript DOM) closes the output stream previously opened using document.open().

 

It has the following syntax. It takes no parameters and does not return a value.

 

document.close(node)

 

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>Close</td><td id="x1"></td></tr>
</table>

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

function addevent() {
  var doc = document.open()
  doc.close()
}
</script>

</body>
</html>

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


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


Desktop view | Switch to Mobile