Latest web development tutorials

HTML DOM open () 메서드

문서 객체 참조 문서 객체

정의 및 사용

open () 메서드는 출력 수집하는 스트림을 엽니 다 document.write를 () 또는 document.writeln을 () 컨텐츠 출력 방법.

공모 () 메서드는 새 문서를 열고 문서의 내용을 설정 한 후 쓰기 () 메소드를 사용하면 사용하는 기억해야한다 () document.close 문서를 닫고 그 내용이 표시 강제하는 방법.

참고 : 대상 파일이 이미 존재하는 경우, 그것은 삭제됩니다.이 방법은 매개 변수가없는 경우 새 창 (: 빈에 대해) 표시됩니다.

문법

document.open(MIMEtype,replace)

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


브라우저 지원

Internet ExplorerFirefoxOperaGoogle ChromeSafari

모든 주요 브라우저는 open () 메서드를 지원


출력 스트림을 열고 텍스트를 추가 한 다음 출력 스트림을 닫습니다

<!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>

»시도

예 2

(; 빈에 대한 새 창), 및 텍스트를 추가 한 다음 출력 스트림을 닫습니다 출력 스트림을 엽니 다

<html>
<body>

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

</body>
</html>

»시도


문서 객체 참조 문서 객체