The close()
method closes the output stream
opened with the document.open() method.
close |
Yes | Yes | Yes | Yes | Yes |
document.close()
None.
No return value.
The following code shows how to open an output stream, add some text, then close the output stream.
<!DOCTYPE html>
<html>
<body>
<button onclick="myFunction()">test</button>
<script>
function myFunction()<!--from w w w . j ava 2s . co m-->
{
var doc=document.open("text/html","replace");
var txt="<html><body>content</body></html>";
doc.write(txt);
doc.close();
}
</script>
</body>
</html>
The code above is rendered as follows:
The following code shows how to open an output stream in a new window, add some text, then close the output stream.
<!DOCTYPE html>
<html>
<body>
<button onclick="myFunction()">test</button>
<!--from www . ja va 2 s . c o m-->
<script>
function myFunction()
{
var w=window.open();
w.document.open();
w.document.write("<h1>Hello World!</h1>");
w.document.close();
}
</script>
</body>
</html>
The code above is rendered as follows: