×
参考手册概览

JavaScript 对象

JavaScript Array 对象手册 JavaScript Array 对象JavaScript Boolean 对象JavaScript Date 对象JavaScript Math 对象JavaScript Number 对象JavaScript String 对象JavaScript RegExp 对象JavaScript 全局属性/函数JavaScript 运算符

Browser 对象

Window 对象Navigator 对象Screen 对象History 对象Location 对象

DOM 对象

HTML DOM DocumentHTML DOM 元素对象HTML DOM 属性对象HTML DOM 事件对象

HTML 对象

<a><area><audio><base><blockquote><body><button><canvas><col><colgroup><datalist><del><details><dialog><embed><fieldset><form><iframe><frameset ><img><ins><input> - button<input> - checkbox<input> - color<input> - date<input> - datetime<input> - datetime-local<input> - email<input> - file<input> - hidden<input> - image<input> - month<input> - number<input> - range<input> - password<input> - radio<input> - reset<input> - search<input> - submit<input> - text<input> - time<input> - url<input> - week<keygen><link><label><legend><li><map><menu><menuItem><meta><meter><object><ol><optgroup><option><param><progress><q><script><select><source><style><table><td><th><tr><textarea><title><time><track><video>

HTML DOM open() 方法


HTML DOM Document 对象HTML DOM Document 对象


定义和用法

open() 方法打开一个输出流来收集 document.write()document.writeln() 方法输出的内容。

调用 open() 方法打开一个新文档并且用 write() 方法设置文档内容后,必须记住用 document.close() 方法关闭文档,并迫使其内容显示出来。

注意:如果目标文件已经存在,它将被清除。如果这个方法没有参数,会显示一个新窗口(about:blank)。

语法

document.open(MIMEtype,replace)

参数 描述
MIMEtype 可选。规定正在写的文档的类型。默认值是 "text/html"。
replace 可选。当此参数设置后,可引起新文档从父文档继承历史条目。


浏览器支持

Internet ExplorerFirefoxOperaGoogle ChromeSafari

所有主要浏览器都支持 open() 方法


实例

实例

打开一个输出流并添加文本,然后关闭输出流:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>外唐教程网(waitang.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>

尝试一下 »

实例 2

打开一个输出流 (一个新窗口; about:blank),并添加文本,然后关闭输出流:

<html>
<body>

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

</body>
</html>

尝试一下 »

HTML DOM Document 对象HTML DOM Document 对象


分类导航

关注微信下载离线手册

bootwiki移动版 bootwiki
(群号:472910771)