HTML DOM Document open() 메서드

정의와 사용법

open() 메서드를 통해 문서를 열고 쓰기 위해 사용합니다.

주의:모든 기존 문서 내용이 지워집니다.

추천:이 메서드를 새 브라우저 창을 엽니다.와 혼동하지 마세요 window.open() 메서드 혼란.

자세히 보기:

Document close() 메서드

Document write() 메서드

Document writeln() 메서드

예제

예제 1

이 문서를 열고 텍스트를 작성한 후 닫습니다:

document.open();
document.write("<h1>Hello World</h1>");
document.close();

직접 시도해 보세요

예제 2

새 창에서 document.open() 사용하기:

const myWindow = window.open();
const myWindow.document.open();
const myWindow.document.write("<h1>Hello World!</h1>");
const myWindow.document.close();

직접 시도해 보세요

예제 3

document.write()를 닫힌 문서에서 사용하면 자동으로 document.open()가 호출됩니다. 이는 기존 내용을 지우게 됩니다。

document.write("<h1>Hello World!</h1>");

직접 시도해 보세요

문법

document.open()
document.open(Mimetype, replace)

파라미터

파라미터 설명
Mimetype 모든 현대 브라우저에서 무시됩니다。
replace 모든 현대 브라우저에서 무시됩니다。

반환 값

없음。

브라우저 지원

document.Open() DOM Level 1 (1998) 기능입니다。

모든 브라우저가 지원합니다:

크롬 IE 에지 파이어폭스 사파리 오페라
크롬 IE 에지 파이어폭스 사파리 오페라
지원 9-11 지원 지원 지원 지원