document.close()
HTML DOM close() 方法
定义和用法
close() 方法用于关闭浏览器窗口。
语法
document.close()
浏览器支持
所有主要浏览器都支持 close() 方法
实例 1
打开一个输出流,添加一些文本,然后关闭输出流:
<html>
<head>
<script>
function createDoc()
{
var doc=document.open("text/html","replace");
var txt="<html><body>Learning about the HTML DOM is fun!</body></html>";
doc.write(txt);
doc.close();
}
</script>
</head>
<body>
<input type="button" value="New document" onclick="createDoc()">
</body>
</html>
<head>
<script>
function createDoc()
{
var doc=document.open("text/html","replace");
var txt="<html><body>Learning about the HTML DOM is fun!</body></html>";
doc.write(txt);
doc.close();
}
</script>
</head>
<body>
<input type="button" value="New document" onclick="createDoc()">
</body>
</html>
实例 2
打开输出流 (新窗口打开; about:blank),添加文本,然后关闭输出流:
<html>
<body>
<script>
var w=window.open();
w.document.open();
w.document.write("<b>Hello World!</b>");
w.document.close();
</script>
</body>
</html>
<body>
<script>
var w=window.open();
w.document.open();
w.document.write("<b>Hello World!</b>");
w.document.close();
</script>
</body>
</html>