HTML DOM open () method
Definition and Usage
open () method opens a stream to collect the output of document.write () or document.writeln () content output method.
Call open () method opens a new document and use the write () method after setting the content of the document, you must remember to use document.close () method to close the document and force its contents displayed.
Note: If the destination file already exists, it is cleared.If this method has no parameters, a new window will appear (about: blank).
grammar
document.open(MIMEtype,replace)
参数 | 描述 |
---|---|
MIMEtype | 可选。规定正在写的文档的类型。默认值是 "text/html"。 |
replace | 可选。当此参数设置后,可引起新文档从父文档继承历史条目。 |
Browser Support
All major browsers support open () method
Examples
Examples
Open an output stream and add text, and then close the output stream:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>本教程(w3big.com)</title>
<script>
function createDoc(){
var doc=document.open("text/html","replace");
var txt="<!DOCTYPE html><html><body>学习 HTML DOM 很有趣!</body></html>";
doc.write(txt);
doc.close();
}
</script>
</head>
<body>
<input type="button" value="新文档" onclick="createDoc()">
</body>
</html>
<html>
<head>
<meta charset="utf-8">
<title>本教程(w3big.com)</title>
<script>
function createDoc(){
var doc=document.open("text/html","replace");
var txt="<!DOCTYPE html><html><body>学习 HTML DOM 很有趣!</body></html>";
doc.write(txt);
doc.close();
}
</script>
</head>
<body>
<input type="button" value="新文档" onclick="createDoc()">
</body>
</html>
try it"
Example 2
Open an output stream (a new window; about: blank), and add text, and then close the output stream:
<html>
<body>
<script>
var w=window.open();
w.document.open();
w.document.write("<h1>Hello World!</h1>");
w.document.close();
</script>
</body>
</html>
<body>
<script>
var w=window.open();
w.document.open();
w.document.write("<h1>Hello World!</h1>");
w.document.close();
</script>
</body>
</html>
try it"
Document Object