HTML DOM close()Method

Document 对象参考手册Document Object

Definition and Usage

close()The method is used to close an output stream opened by adocument.openmethod, and display the selected data.

Syntax

document.close()


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support the close() method.


Examples

Example 1

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

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Rookie Tutorial (example.com)</title>
<script>
function createDoc(){
    var doc=document.open("text/html","replace");
var txt="<!DOCTYPE html><html><body>Learning HTML DOM is very interesting!</body></html>";
    doc.write(txt);
    doc.close();
}
</script>
</head>

<body>
<input type="button" value="New document" onclick="createDoc()">
</body>
</html>

Try it Yourself »

Example 2

Open the output stream (open in a new window; about:blank), add text, then close the output stream:

<html>
<body>

<script>
var w=window.open();
w.document.open();
w.document.write("<b>Hello World!</b>");
w.document.close();
</script>

</body>
</html>

Try it Yourself »


Document 对象参考手册Document Object Other Extensions