DOM

Document() コンストラクター

  編集:2022.09.06 by T.A.

新しい Document オブジェクトを作成して返します。

ブラウザーに読み込まれたウェブページである Document オブジェクトを新たに生成し、そのページの内容へのエントリー ポイントを提供します。

new Document()
D=new Document();
D.write("テスト"); //エラー発生:Failed to execute 'write' on 'Document': Only HTML documents support write().
	//「ドキュメント」で「書き込み」を実行できませんでした: HTML ドキュメントのみが write() をサポートしています。

¶どういうことだろうか?

D=new Document();
document.open();
document.write(D);
document.close();
alert(document.children.length);
alert(document.children[0].tagName);

ダイアログに「1」と表示され、

ダイアログに「HTML」と表示され、

新しい画面になり、「[object Document]」と表示された。

D=new Document();
document=D;	//=[object]:[object Document]
	//location=[object]:null
	//implementation=[object]:[object DOMImplementation]
	//URL=[string]:about:blank
	//documentURI=[string]:about:blank
	//…

当文書は何も変わらず。

¶new Document()に利用法があるのだろうか?


テスト