DHTML: documentオブジェクト  編集:2021.08.19 by T.A.
document= /[Edge]
=[object]:[object HTMLDocument]

location=[object]:file:///C:/Users/asmin/Documents/%E3%83%91%E3%82%BD%E3%82%B3%E3%83%B3%E9%96%A2%E4・・・

implementation=[object]:[object DOMImplementation]

URL=[string]:file:///C:/Users/asmin/Documents/%E3%83%91%E3%82%BD%E3%82%B3%E3%83%B3%E9%96%A2%E4・・・

documentURI=[string]:file:///C:/Users/asmin/Documents/%E3%83%91%E3%82%BD%E3%82%B3%E3%83%B3%E9%96%A2%E4・・・

compatMode=[string]:CSS1Compat

characterSet=[string]:UTF-8

charset=[string]:UTF-8

inputEncoding=[string]:UTF-8

contentType=[string]:text/html

doctype=[object]:[object DocumentType]

documentElement=[object]:[object HTMLHtmlElement]

xmlEncoding=[object]:null

xmlVersion=[object]:null

xmlStandalone=[boolean]:false

domain=[string]:

referrer=[string]:

cookie=[string]:

lastModified=[string]:08/19/2021 18:29:03

readyState=[string]:complete

title=[string]:DHTML:documentオブジェクト

dir=[string]:

body=[object]:[object HTMLBodyElement]

head=[object]:[object HTMLHeadElement]

images=[object]:[object HTMLCollection]

embeds=[object]:[object HTMLCollection]

plugins=[object]:[object HTMLCollection]

links=[object]:[object HTMLCollection]

forms=[object]:[object HTMLCollection]

scripts=[object]:[object HTMLCollection]

currentScript=[object]:null

defaultView=[object]:[object Window]

designMode=[string]:off

onreadystatechange=[object]:null

anchors=[object]:[object HTMLCollection]

applets=[object]:[object HTMLCollection]

fgColor=[string]:

linkColor=[string]:

vlinkColor=[string]:

alinkColor=[string]:

bgColor=[string]:

all=[undefined]:[object HTMLAllCollection]

scrollingElement=[object]:[object HTMLHtmlElement]

onpointerlockchange=[object]:null

onpointerlockerror=[object]:null

hidden=[boolean]:false

visibilityState=[string]:visible

wasDiscarded=[boolean]:false

featurePolicy=[object]:[object FeaturePolicy]

webkitVisibilityState=[string]:visible

webkitHidden=[boolean]:false

onbeforecopy=[object]:null

onbeforecut=[object]:null

onbeforepaste=[object]:null

onfreeze=[object]:null

onresume=[object]:null

onsearch=[object]:null

onsecuritypolicyviolation=[object]:null

onvisibilitychange=[object]:null

fullscreenEnabled=[boolean]:true

fullscreen=[boolean]:false

onfullscreenchange=[object]:null

onfullscreenerror=[object]:null

webkitIsFullScreen=[boolean]:false

webkitCurrentFullScreenElement=[object]:null

webkitFullscreenEnabled=[boolean]:true

webkitFullscreenElement=[object]:null

onwebkitfullscreenchange=[object]:null

onwebkitfullscreenerror=[object]:null

rootElement=[object]:null

onbeforexrselect=[object]:null

onabort=[object]:null

onblur=[object]:null

oncancel=[object]:null

oncanplay=[object]:null

oncanplaythrough=[object]:null

onchange=[object]:null

onclick=[object]:null

onclose=[object]:null

oncontextmenu=[object]:null

oncuechange=[object]:null

ondblclick=[object]:null

ondrag=[object]:null

ondragend=[object]:null

ondragenter=[object]:null

ondragleave=[object]:null

ondragover=[object]:null

ondragstart=[object]:null

ondrop=[object]:null

ondurationchange=[object]:null

onemptied=[object]:null

onended=[object]:null

onerror=[object]:null

onfocus=[object]:null

onformdata=[object]:null

oninput=[object]:null

oninvalid=[object]:null

onkeydown=[object]:null

onkeypress=[object]:null

onkeyup=[object]:null

onload=[object]:null

onloadeddata=[object]:null

onloadedmetadata=[object]:null

onloadstart=[object]:null

onmousedown=[object]:null

onmouseenter=[object]:null

onmouseleave=[object]:null

onmousemove=[object]:null

onmouseout=[object]:null

onmouseover=[object]:null

onmouseup=[object]:null

onmousewheel=[object]:null

onpause=[object]:null

onplay=[object]:null

onplaying=[object]:null

onprogress=[object]:null

onratechange=[object]:null

onreset=[object]:null

onresize=[object]:null

onscroll=[object]:null

onseeked=[object]:null

onseeking=[object]:null

onselect=[object]:null

onstalled=[object]:null

onsubmit=[object]:null

onsuspend=[object]:null

ontimeupdate=[object]:null

ontoggle=[object]:null

onvolumechange=[object]:null

onwaiting=[object]:null

onwebkitanimationend=[object]:null

onwebkitanimationiteration=[object]:null

onwebkitanimationstart=[object]:null

onwebkittransitionend=[object]:null

onwheel=[object]:null

onauxclick=[object]:null

ongotpointercapture=[object]:null

onlostpointercapture=[object]:null

onpointerdown=[object]:null

onpointermove=[object]:null

onpointerup=[object]:null

onpointercancel=[object]:null

onpointerover=[object]:null

onpointerout=[object]:null

onpointerenter=[object]:null

onpointerleave=[object]:null

onselectstart=[object]:null

onselectionchange=[object]:null

onanimationend=[object]:null

onanimationiteration=[object]:null

onanimationstart=[object]:null

ontransitionrun=[object]:null

ontransitionstart=[object]:null

ontransitionend=[object]:null

ontransitioncancel=[object]:null

oncopy=[object]:null

oncut=[object]:null

onpaste=[object]:null

children=[object]:[object HTMLCollection]

firstElementChild=[object]:[object HTMLHtmlElement]

lastElementChild=[object]:[object HTMLHtmlElement]

childElementCount=[number]:1

activeElement=[object]:[object HTMLButtonElement]

styleSheets=[object]:[object StyleSheetList]

pointerLockElement=[object]:null

fullscreenElement=[object]:null

adoptedStyleSheets=[object]:

fonts=[object]:[object FontFaceSet]

adoptNode=[function]:function adoptNode() { [native code] }

append=[function]:function append() { [native code] }

captureEvents=[function]:function captureEvents() { [native code] }

caretRangeFromPoint=[function]:function caretRangeFromPoint() { [native code] }

clear=[function]:function clear() { [native code] }

close=[function]:function close() { [native code] }

createAttribute=[function]:function createAttribute() { [native code] }

createAttributeNS=[function]:function createAttributeNS() { [native code] }

createCDATASection=[function]:function createCDATASection() { [native code] }

createComment=[function]:function createComment() { [native code] }

createDocumentFragment=[function]:function createDocumentFragment() { [native code] }

createElement=[function]:function createElement() { [native code] }

createElementNS=[function]:function createElementNS() { [native code] }

createEvent=[function]:function createEvent() { [native code] }

createExpression=[function]:function createExpression() { [native code] }

createNSResolver=[function]:function createNSResolver() { [native code] }

createNodeIterator=[function]:function createNodeIterator() { [native code] }

createProcessingInstruction=[function]:function createProcessingInstruction() { [native code] }

createRange=[function]:function createRange() { [native code] }

createTextNode=[function]:function createTextNode() { [native code] }

createTreeWalker=[function]:function createTreeWalker() { [native code] }

elementFromPoint=[function]:function elementFromPoint() { [native code] }

elementsFromPoint=[function]:function elementsFromPoint() { [native code] }

evaluate=[function]:function evaluate() { [native code] }

execCommand=[function]:function execCommand() { [native code] }

exitFullscreen=[function]:function exitFullscreen() { [native code] }

exitPointerLock=[function]:function exitPointerLock() { [native code] }

getElementById=[function]:function getElementById() { [native code] }

getElementsByClassName=[function]:function getElementsByClassName() { [native code] }

getElementsByName=[function]:function getElementsByName() { [native code] }

getElementsByTagName=[function]:function getElementsByTagName() { [native code] }

getElementsByTagNameNS=[function]:function getElementsByTagNameNS() { [native code] }

getSelection=[function]:function getSelection() { [native code] }

hasFocus=[function]:function hasFocus() { [native code] }

importNode=[function]:function importNode() { [native code] }

open=[function]:function open() { [native code] }

prepend=[function]:function prepend() { [native code] }

queryCommandEnabled=[function]:function queryCommandEnabled() { [native code] }

queryCommandIndeterm=[function]:function queryCommandIndeterm() { [native code] }

queryCommandState=[function]:function queryCommandState() { [native code] }

queryCommandSupported=[function]:function queryCommandSupported() { [native code] }

queryCommandValue=[function]:function queryCommandValue() { [native code] }

querySelector=[function]:function querySelector() { [native code] }

querySelectorAll=[function]:function querySelectorAll() { [native code] }

releaseEvents=[function]:function releaseEvents() { [native code] }

replaceChildren=[function]:function replaceChildren() { [native code] }

webkitCancelFullScreen=[function]:function webkitCancelFullScreen() { [native code] }

webkitExitFullscreen=[function]:function webkitExitFullscreen() { [native code] }

write=[function]:function write() { [native code] }

writeln=[function]:function writeln() { [native code] }

fragmentDirective=[object]:[object FragmentDirective]

onpointerrawupdate=[object]:null

pictureInPictureEnabled=[boolean]:true

pictureInPictureElement=[object]:null

timeline=[object]:[object DocumentTimeline]

hasStorageAccess=[function]:function hasStorageAccess() { [native code] }

requestStorageAccess=[function]:function requestStorageAccess() { [native code] }

getAnimations=[function]:function getAnimations() { [native code] }

exitPictureInPicture=[function]:function exitPictureInPicture() { [native code] }

nodeType=[number]:9

nodeName=[string]:#document

baseURI=[string]:file:///C:/Users/asmin/Documents/%E3%83%91%E3%82%BD%E3%82%B3%E3%83%B3%E9%96%A2%E4・・・

isConnected=[boolean]:true

ownerDocument=[object]:null

parentNode=[object]:null

parentElement=[object]:null

childNodes=[object]:[object NodeList]

firstChild=[object]:[object DocumentType]

lastChild=[object]:[object HTMLHtmlElement]

previousSibling=[object]:null

nextSibling=[object]:null

nodeValue=[object]:null

textContent=[object]:null

ELEMENT_NODE=[number]:1

ATTRIBUTE_NODE=[number]:2

TEXT_NODE=[number]:3

CDATA_SECTION_NODE=[number]:4

ENTITY_REFERENCE_NODE=[number]:5

ENTITY_NODE=[number]:6

PROCESSING_INSTRUCTION_NODE=[number]:7

COMMENT_NODE=[number]:8

DOCUMENT_NODE=[number]:9

DOCUMENT_TYPE_NODE=[number]:10

DOCUMENT_FRAGMENT_NODE=[number]:11

NOTATION_NODE=[number]:12

DOCUMENT_POSITION_DISCONNECTED=[number]:1

DOCUMENT_POSITION_PRECEDING=[number]:2

DOCUMENT_POSITION_FOLLOWING=[number]:4

DOCUMENT_POSITION_CONTAINS=[number]:8

DOCUMENT_POSITION_CONTAINED_BY=[number]:16

DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC=[number]:32

appendChild=[function]:function appendChild() { [native code] }

cloneNode=[function]:function cloneNode() { [native code] }

compareDocumentPosition=[function]:function compareDocumentPosition() { [native code] }

contains=[function]:function contains() { [native code] }

getRootNode=[function]:function getRootNode() { [native code] }

hasChildNodes=[function]:function hasChildNodes() { [native code] }

insertBefore=[function]:function insertBefore() { [native code] }

isDefaultNamespace=[function]:function isDefaultNamespace() { [native code] }

isEqualNode=[function]:function isEqualNode() { [native code] }

isSameNode=[function]:function isSameNode() { [native code] }

lookupNamespaceURI=[function]:function lookupNamespaceURI() { [native code] }

lookupPrefix=[function]:function lookupPrefix() { [native code] }

normalize=[function]:function normalize() { [native code] }

removeChild=[function]:function removeChild() { [native code] }

replaceChild=[function]:function replaceChild() { [native code] }

addEventListener=[function]:function addEventListener() { [native code] }

dispatchEvent=[function]:function dispatchEvent() { [native code] }

removeEventListener=[function]:function removeEventListener() { [native code] }


内容表示
表示内容:
表示内容:

以下は、プロパティーとメソッド。
document documentオブジェクト。

文書を開く/閉じる

openメソッド
文書を開く
document.open(MIMEタイプ)
¶document.write() で書いても、必ず document.close() で閉じないと最後の書き込み内容が反映されない事があるらしい。後にまだ続く、と判断されているらしい。
¶このまま document.open() を実行すると現在のウィンドウに表示される。
【例】 別表示にて。
<TABLE class=Koma><CAPTION>JavaScript実行:open()</CAPTION> <TR><TD><TEXTAREA class=Sou> D=WObj=window.open(); </TEXTAREA><BUTTON class=Btn onclick="JaExDispD(this)">D</BUTTON> </TABLE> <TABLE class=Koma><CAPTION>JavaScript実行:書き込み</CAPTION> <TR><TD><TEXTAREA class=Sou> D=WObj.document.write("画像<IMG src='../サンプル/RGB.gif'>"); </TEXTAREA><BUTTON class=Btn onclick="JaExDispD(this)">D</BUTTON> </TABLE> <TABLE class=Koma><CAPTION>JavaScript実行:close()</CAPTION> <TR><TD><TEXTAREA class=Sou> D=WObj.document.close(); </TEXTAREA><BUTTON class=Btn onclick="JaExDispD(this)">D</BUTTON> </TABLE> <TABLE class=Koma> <TR><TD>内容<INPUT class=SouI value="WObj.document"><BUTTON class=Btn onclick="DispObjList(this)">表</BUTTON><BR> 内容<INPUT class=SouI value="WObj.document.outerHTML"><BUTTON class=Btn onclick="DispObjList(this)">表</BUTTON> <DIV class=内容1></DIV> </TABLE> <TABLE class=Koma><CAPTION>JavaScript実行:ウインドウを閉じる</CAPTION> <TR><TD><TEXTAREA class=Sou> D=WObj.close(); </TEXTAREA><BUTTON class=Btn onclick="JaExDispD(this)">D</BUTTON> </TABLE>
closeメソッド
現在の文書出力終了を示す。
document.close()
【例】参照→open、writeメソッド

書き込み関係

writeメソッド
文書に文字列を表示する。
document.write(text)
text 表示内容(文字列、HTML文章、数値など)。
数値の場合はその値が表示される。
,」(コンマ)で区切って並べる事も可能。
(オブジェクトの場合は「[object]」と文字列表示された。)
ソースコードとして文書に組み込まれる。「<」「>」などを使用したタグ文字で書き込むとそれが要素となる。つまり、スクリプトでソースコードの生成も可能となる。参照:要素の作成など→メソッド
現在開かれている文書で実行した場合は、新しく文書が作成されその文書に書き込まれる。
close() を実行されると文書は閉じられ(画面では表示されている)、次からはその文書には書き込めず、新しい文書が開かれる事になる。
文書読み込み時にスクリプトで document.write() を実行させると、その文書に書き込まれる。
【用例】 Str="test漢字"; document.write("文字列:",Str); 【例
<TABLE class=Koma><CAPTION>JavaScript実行:別ウィンドウを開く</CAPTION> <TR><TD><TEXTAREA class=Sou> WObj=window.open("","Sample"); D="" </TEXTAREA><BUTTON class=Btn onclick="JaExDispD(this)">D</BUTTON> </TABLE> <TABLE class=Koma><CAPTION>JavaScript実行:write()</CAPTION> <TR><TD><TEXTAREA class=Sou> WObj.document.write(123,"文字"); D="" </TEXTAREA><BUTTON class=Btn onclick="JaExDispD(this)">D</BUTTON> </TABLE> <TABLE class=Koma><CAPTION>JavaScript実行:書き込み+改行</CAPTION> <TR><TD><TEXTAREA class=Sou> WObj.document.writeln(123,"文字↓"); D="" </TEXTAREA><BUTTON class=Btn onclick="JaExDispD(this)">D</BUTTON> </TABLE> <TABLE class=Koma><CAPTION>JavaScript実行:文書閉じる</CAPTION> <TR><TD><TEXTAREA class=Sou> WObj.document.close(); </TEXTAREA><BUTTON class=Btn onclick="JaExDispD(this)">D</BUTTON> </TABLE> <TABLE class=Koma> <TR><TD>内容<INPUT class=SouI value="WObj.document"><BUTTON class=Btn onclick="DispObjList(this)">表</BUTTON><BR> 内容<INPUT class=SouI value="WObj.document.body.innerHTML"><BUTTON class=Btn onclick="DispObjList(this)">表</BUTTON> <DIV class=内容1></DIV> </TABLE>
writelnメソッド
改行付きの文字列を表示する。
document.writeln(text)
改行コード付き。他は document.write() と同じ。
¶普通のHTML内では改行は無効。XMP 要素などに有効の様だ。
参照→writeメソッド
clearメソッド
現在の文書を消去する。
document.clear()
【例
<TABLE class=Koma><CAPTION>JavaScript実行:</CAPTION> <TR><TD><TEXTAREA class=Sou> WObj=window.open(); D=""; </TEXTAREA><BUTTON class=Btn onclick="JaExDispD(this)">D</BUTTON> </TABLE> <TABLE class=Koma><CAPTION>JavaScript実行:</CAPTION> <TR><TD><TEXTAREA class=Sou> WObj.document.write("テスト"); </TEXTAREA><BUTTON class=Btn onclick="JaExDispD(this)">D</BUTTON> </TABLE> <TABLE class=Koma><CAPTION>JavaScript実行:</CAPTION> <TR><TD><TEXTAREA class=Sou> WObj.document.close(); </TEXTAREA><BUTTON class=Btn onclick="JaExDispD(this)">D</BUTTON> </TABLE> <TABLE class=Koma><CAPTION>JavaScript実行:</CAPTION> <TR><TD><TEXTAREA class=Sou> WObj.document.clear(); </TEXTAREA><BUTTON class=Btn onclick="JaExDispD(this)">D</BUTTON> </TABLE> <TABLE class=Koma> <TR><TD>内容<INPUT class=SouI value="WObj"><BUTTON class=Btn onclick="DispObjList(this)">表</BUTTON><BR> 内容<INPUT class=SouI value="WObj.document.readyState"><BUTTON class=Btn onclick="DispObjList(this)">表</BUTTON> <DIV class=内容1></DIV> </TABLE> <TABLE class=Koma><CAPTION>JavaScript実行:</CAPTION> <TR><TD><TEXTAREA class=Sou> WObj.clear(); </TEXTAREA><BUTTON class=Btn onclick=" JaExDispD(this)">D</BUTTON> </TABLE> ¶意味不明。

情報関係

parentWindowプロパティ
文書が含まれるウィンドウを返す。
document.parentWindow
【例
<TABLE class=Koma> <TR><TD>内容<INPUT class=SouI value="document.parentWindow"><BUTTON class=Btn onclick="DispObjList(this)">表</BUTTON><BR> 内容<INPUT class=SouI value="document.parentWindow.document.body.outerHTML"><BUTTON class=Btn onclick="DispObjList(this)">表</BUTTON> <DIV class=内容1></DIV> </TABLE>
URLプロパティ
現在の文書のURLを返す。
document.URL=URL
このプロパティはウィンドウの location.href プロパティのエイリアス(¶別名?)である。
¶この文字使用には不明な点もある。
【例
<TABLE class=Koma> <TR><TD>内容<INPUT class=SouI value="document.URL"><BUTTON class=Btn onclick="DispObjList(this)">表</BUTTON> <DIV class=内容1></DIV> </TABLE>
mimeTypeプロパティ
¶現在の文書のMIMEタイプを返す。
document.mimeType
¶戻り値 備考
Microsoft HTML Document 5.0 IE5.0の場合
HTML Document IE5.5の場合
HTML ドキュメント IE10の場合
【例
<TABLE class=Koma> <TR><TD>内容<INPUT class=SouI value="document.mimeType"><BUTTON class=Btn onclick="DispObjList(this)">表</BUTTON> <DIV class=内容1></DIV> </TABLE>
referrerプロパティ
直前に参照していたページのURLを返す。
document.referrer
【例
<TABLE class=Koma><CAPTION>JavaScript実行:</CAPTION> <TR><TD><TEXTAREA class=Sou> WObj=window.open("../サンプル/サンプル.htm"); D="" </TEXTAREA><BUTTON class=Btn onclick="JaExDispD(this)">D</BUTTON> </TABLE> <TABLE class=Koma> <TR><TD>内容<INPUT class=SouI value="document.referrer"><BUTTON class=Btn onclick="DispObjList(this)">表</BUTTON> <DIV class=内容1></DIV> </TABLE> ¶不明。
locationプロパティ
現在の文書の URL の情報を返す。→locationオブジェクト
document.location=URL情報
locationオブジェクトを読み出すキーワード。
【例
<TABLE class=Koma> <TR><TD>内容<INPUT class=SouI value="document.location"><BUTTON class=Btn onclick="DispObjList(this)">表</BUTTON> <DIV class=内容1></DIV> </TABLE>
charsetプロパティ
文書の文字コードセットを返す。
document.charset
【例
<TABLE class=Koma> <TR><TD>内容<INPUT class=SouI value="document.charset"><BUTTON class=Btn onclick="DispObjList(this)">表</BUTTON> <DIV class=内容1></DIV> </TABLE>
defaultCharsetプロパティ
文書の文字セットの初期値を読み出す。
document.defaultCharset
【¶戻り値】autodetect:自動検出?。
【例
<TABLE class=Koma> <TR><TD>内容<INPUT class=SouI value="document.defaultCharset"><BUTTON class=Btn onclick="DispObjList(this)">表</BUTTON> <DIV class=内容1></DIV> </TABLE>
domainプロパティ
文書のセキュリティドメインを設定/読み出する。
document.domain=ドメイン
このプロパティは読み書き可能。
初期値はそのドキュメントを送信したサーバーとなる。
この domain プロパティによって、フレーム間でページを共有することが可能になる。例えば、1つのフレーム内にある「home.microsoft.com」からのページと、「www.microsoft.com」から送られたページは始めはお互いに通信できないが、両方のページの domain プロパティを「microsoft.com」に設定すれば、両方のページはセキュリティ付きで相互に通信できるようになる。
【例
<TABLE class=Koma> <TR><TD>内容<INPUT class=SouI value="document.domain"><BUTTON class=Btn onclick="DispObjList(this)">表</BUTTON> <DIV class=内容1></DIV> </TABLE>

色関係

bgColorプロパティ
文書の背景色を返す。
document.bgColor
【例
<TABLE class=Koma> <TR><TD>内容<INPUT class=SouI value="document.bgColor"><BUTTON class=Btn onclick="DispObjList(this)">表</BUTTON><BR> 内容<INPUT class=SouI value="document.fgColor"><BUTTON class=Btn onclick="DispObjList(this)">表</BUTTON> <DIV class=内容1></DIV> </TABLE>
fgColorプロパティ
文書のテキスト色を返す。
document.fgColor

リンクの色関係

linkColorプロパティ
文書のリンクの色を返す。colorの取り得る値は、カラーテーブルにある色の名前または値。
document.linkColor=
カラーテーブルにある色の名前または値。
【例
<TABLE class=Koma> <TR><TD>内容<INPUT class=SouI value="document.linkColor"><BUTTON class=Btn onclick="DispObjList(this)">表</BUTTON><BR> 内容<INPUT class=SouI value="document.alinkColor"><BUTTON class=Btn onclick="DispObjList(this)">表</BUTTON><BR> 内容<INPUT class=SouI value="document.vlinkColor"><BUTTON class=Btn onclick="DispObjList(this)">表</BUTTON> <DIV class=内容1></DIV> </TABLE>
alinkColorプロパティ
文書のアクティブリンクの色を設定する。
document.alinkColor=
カラーテーブルにある色の名前または値。
vlinkColorプロパティ
文書の表示済みのリンクの色を設定/設定を読み出す。
document.vlinkColor=
カラーテーブルにある色の名前または値。

スタイルシート関係

メソッド
現在の文書にスタイルシートを適用する。
document.createStyleSheet(URL,挿入位置)
URL 適用するスタイルシートへのURL(またはスタイル指定)
挿入位置 数値指定。StyleSheet コレクションへの挿入位置。初期値:最終インデックス。
【用例】 document.createStyleSheet(document.body.style.color='#ff0000');

要素関係

createElementメソッド
要素を生成し、そのオブジェクトを返す。
document.createElement(要素名)
要素名 文字列として指定
この生成された状態では文書には組み込まれていない。生成した要素を文書に挿入したりする事で文書に組み込まれ、オブジェクトはその組み込まれた文書内を示す様だ。
【例
<TABLE class=Koma><CAPTION>JavaScript実行:要素生成</CAPTION> <TR><TD><TEXTAREA class=Sou> TO=document.createElement("B"); D=TO; </TEXTAREA><BUTTON class=Btn onclick="JaExDispD(this)">D</BUTTON> </TABLE> <TABLE class=Koma><CAPTION>JavaScript実行:テキストとスタイル</CAPTION> <TR><TD><TEXTAREA class=Sou> TO.innerText="緑文字"; TO.style.color="green"; D=TO </TEXTAREA><BUTTON class=Btn onclick="JaExDispD(this)">D</BUTTON> </TABLE> <TABLE class=Koma> <TR><TD>内容<INPUT class=SouI value="TO.tagName"><BUTTON class=Btn onclick="DispObjList(this)">表</BUTTON> <DIV class=内容1></DIV> </TABLE> <TABLE class=Koma> <TR><TD>内容<INPUT class=SouI value="TO.outerHTML"><BUTTON class=Btn onclick="DispObjList(this)">表</BUTTON> <DIV class=内容2></DIV> </TABLE> 関連→「メソッド」の要素関連
activeElementプロパティ
現在アクティブになっている要素を返す。
document.activeElement
【例
<TABLE class=Koma><CAPTION>HTMLの組み込み:</CAPTION> <TD><TEXTAREA id=IactiveElementHT class=Sou> <SPAN id=IactiveElementSPAN>[SPAN要素:id=IactiveElementSPAN]</SPAN><BR> <INPUT id=IactiveElementINPUT>[INPUT要素:id=IactiveElementINPUT]</SPAN> </TEXTAREA><BUTTON class=Btn onclick="CopyHT(IactiveElementG,IactiveElementHT)">表</BUTTON> </TABLE> <TABLE class=画面><TR><TD id=IactiveElementG class=画面>ここに表示 </TABLE> <TABLE class=Koma><CAPTION>JavaScript実行:サンプルをフォーカスさせて調べます</CAPTION> <TR><TD><TEXTAREA class=Sou> IactiveElementSPAN.focus(); D=document.activeElement.tagName; </TEXTAREA><BUTTON class=Btn onclick="JaExDispD(this)">D</BUTTON> </TABLE> <TABLE class=Koma><CAPTION>JavaScript実行:サンプルをフォーカスさせて調べます</CAPTION> <TR><TD><TEXTAREA class=Sou> IactiveElementINPUT.focus(); D=document.activeElement.tagName; </TEXTAREA><BUTTON class=Btn onclick="JaExDispD(this)">D</BUTTON> </TABLE>
elementFromPointメソッド
[IE]、[FF]×。ページ内座標の要素オブジェクトを返す。
document.elementFromPoint(x,y)
x ページ内の座標X 値。
y ページ内の座標Y 値。
【備考】¶座標値は、ページの表示エリアの左上が座標(2,2)のようだ。2=document.body.clientLeft、document.body.clientTopの値。この値はイベントで取得できるevent.clientX、event.clientYを利用できる。よって、
Obj=document.elementFromPoint(event.clientX,event.clientY) で取得できる。
¶返るオブジェクトは、座標によってはnullとなる場合がある。
参照→window.event.xwindow.event.clientX
【例】 マウス位置の要素を表示します。
<TABLE class=KomaW><CAPTION>スクリプトの組み込み:</CAPTION> <TR><TD><TEXTAREA id=elFrPoTS> function elFrPoJ(){ MX=window.event.x; MY=window.event.y; elFrPoTwex.innerHTML=MX; elFrPoTwey.innerHTML=MY; TObj=document.elementFromPoint(MX,MY); elFrPoTTO.innerHTML=TObj; if(TObj.tagName){elFrPoTTOtN.innerHTML=TObj.tagName}else{elFrPoTTOtN.innerHTML=typeof TObj.tagName} if(TObj.offsetParent){elFrPoTTOoPtN.innerText=TObj.offsetParent.tagName}else{elFrPoTTOoPtN.innerText=typeof TObj.offsetParent.tagName}; } </TEXTAREA><BUTTON onclick="CopyST(elFrPoSC,elFrPoTS)">組</BUTTON> </TABLE> <TABLE class=KomaW><CAPTION>HTMLの表示組み込み:</CAPTION> <TR><TD><TEXTAREA id=elFrPoT> <DIV id=elFrPoTK onmousemove="elFrPoJ()" style="cursor:default; background-color:yellow"> <TT>MX=window.event.x</TT>:<SPAN id="elFrPoTwex">0</SPAN><BR> <TT>MY=window.event.y</TT>:<SPAN id="elFrPoTwey">0</SPAN><BR> <TT>TObj=document.elementFromPoint(MX,MY)</TT><BR> <B>TObj:</B><SPAN id="elFrPoTTO"></SPAN><BR> <B>TObj.tagName:</B><SPAN id="elFrPoTTOtN"></SPAN><BR> <B>TObj.offsetParent.tagName:</B><SPAN id="elFrPoTTOoPtN"></SPAN> </DIV> </TEXTAREA><BUTTON onclick="CopyHT(elFrPoG,elFrPoT)">表</BUTTON> </TABLE> <TABLE class=画面><TR><TD class=画面 id=elFrPoG>ここに表示 </TABLE> <TABLE class=Koma> <TR><TD>内容<INPUT class=SouI value="elFrPoTK"><BUTTON class=Btn onclick="DispObjList(this)">表</BUTTON> <DIV class=内容1></DIV> </TABLE>
createTextNodeメソッド
指定の文字列を持ったテキストノードを生成する。
document.createTextNode(text)
text nodeValue の値。HTML文も可能の様だ。
¶オブジェクトとして得られた。
【用例】 var tnObj=document.createTextNode("追加テキスト"); dlObj.insertBefore(tnObj); 【例
<TABLE class=KomaW><CAPTION>HTMLの組み込み:</CAPTION> <TD><TEXTAREA id=IcreateTextNodeHT> 始<SPAN id="crTeNoOS1" style="background-color:#DDD">要素1</SPAN>終<BR> </TEXTAREA><BUTTON class=Btn onclick="CopyHT(IcreateTextNodeG,IcreateTextNodeHT)">表</BUTTON> </TABLE> <TABLE class=画面><TR><TD id=IcreateTextNodeG class=画面>ここに表示 </TABLE> <TABLE class=Koma><CAPTION>JavaScript実行:テキストノード生成</CAPTION> <TR><TD><TEXTAREA class=Sou> NObj=document.createTextNode("文字列"); D=NObj </TEXTAREA><BUTTON class=Btn onclick="JaExDispD(this)">D</BUTTON> </TABLE> <TABLE class=Koma><CAPTION>JavaScript実行:テキストノード挿入。(afterBegin は開始タグの直後。beforeEnd は終了タグの直前)</CAPTION> <TR><TD><TEXTAREA class=Sou> crTeNoOS1.insertAdjacentHTML("afterBegin",NObj.data); D="" </TEXTAREA><BUTTON class=Btn onclick="JaExDispD(this)">D</BUTTON> </TABLE> <TABLE class=Koma> <TR><TD>内容<INPUT class=SouI value="NObj.nodeValue"><BUTTON class=Btn onclick="DispObjList(this)">表</BUTTON><BR> 内容<INPUT class=SouI value="crTeNoOS1.outerHTML"><BUTTON class=Btn onclick="DispObjList(this)">表</BUTTON> <DIV class=内容1></DIV> </TABLE>
documentElementプロパティ
文書のルートノードへの参照を返す。
document.documentElement
【例】 ¶詳細不明。
<TABLE class=Koma> <TR><TD>内容<INPUT class=SouI value="document.documentElement.tagName"><BUTTON class=Btn onclick="DispObjList(this)">表</BUTTON> <DIV class=内容1></DIV> </TABLE>

プロパティ関係

expandoプロパティ
オブジェクト内でプロパティを作成するか否かを指定する。
document.expando=作成指定
作成指定 true|false。初期値:true。
【解説】オブジェクトにプロパティを追加することができる。
例えば、Obj.style.borderColor='blue' とすると、枠色が青になる。これを、Obj.style.bordercolor='blue' とすると、style オブジェクトに bordercolor プロパティが作られる。しかし、ここに値を指定しても。枠色は変わらない。追加されたプロパティは全く別のものだ。
¶この expando プロパティが false なのに、プロパティを追加するとエラーになる。しかし、一度作ってしまったプロパティの値を変更する事は可能だった。
【例
<TABLE class=Koma><CAPTION>JavaScript実行:</CAPTION> <TR><TD><TEXTAREA class=Sou> document.expando=true; D="" </TEXTAREA><BUTTON class=Btn onclick="JaExDispD(this)">D</BUTTON> </TABLE> <TABLE class=Koma><CAPTION>JavaScript実行:「test」プロパティ追加</CAPTION> <TR><TD><TEXTAREA class=Sou> document.test="文字列"; D="" </TEXTAREA><BUTTON class=Btn onclick="JaExDispD(this)">D</BUTTON> </TABLE> <TABLE class=Koma> <TR><TD>内容<INPUT class=SouI value="document.test"><BUTTON class=Btn onclick="DispObjList(this)">表</BUTTON> <DIV class=内容1></DIV> </TABLE>

属性関係

recalcメソッド
文書中の全てのダイナミック属性値を再適用する¶。
document.recalc()

クッキー関係

cookieプロパティ
クッキー(cookie)の文字情報を指定する。
document.cookie=cookie
cookie はブラウザに蓄積される小さな情報である。
1つのCookieには4096バイトのデータを記録でき、最大で300のCookieを保存できる。1台のサーバが同じコンピュータに対して発行できるCookieの数は20個に制限されている(¶調べた結果、1つのクッキーファイルに20個までだった)。
MS:cookie は次のような構成になっている。name=value 以外はすべてオプションである。引数はセミコロン「;」で区切られている。
name=value;
それぞれの cookie はname=value の対で保存される。例えば、cookie が「foo」で、その値に「bar」を保存したい場合には「foo=bar」という形にする。このname=value の対の数の制限はない。しかし、cookies は 1 つの文字列として連結されて送られるので、個々の値を知りたい場合に見つけるのが大変になる。
Expires=date;
期限が設定されていない場合には、ブラウザが閉じられた時点で cookie は消える。未来の期限が設定されている場合には保存され、複数回のセッションでも消えない。もし、過去の期限を設定した場合には cookie は消されてしまう。期限は GMT フォーマットで指定しなければならない。
domain=domainname;
ドメイン名を指定すると、複数のサーバーで構成されているドメイン内の複数のページで 1 つの cookie 情報を共有することができる。
path=path;
cookie のパスを設定すると、同じドメイン内において、現在のドキュメントが他のページと cookie 情報を共有することができるようになる。つまり、パスが「/foobar」となっていた場合、「/foobar」内とそのサブフォルダ内の全てのページは同じ cookie 情報にアクセスできるようになる。
secure;
cookie を「secure」に指定すると、その cookie 情報に対してセキュリティの保たれた環境でなければアクセスできないようになる。
【注意事項】文字列操作 substring、charAt、indexOf、lastIndexOf などが cookie に保存する値の処理に使える。
【例】 10秒間だけ存在するクッキーを登録します。
<TABLE class=Koma><CAPTION>JavaScript実行:現在の時刻+10秒。</CAPTION> <TR><TD><TEXTAREA class=Sou> D=new Date().getTime()+1000*10 </TEXTAREA><BUTTON class=Btn onclick="JaExDispD(this)">D</BUTTON> </TABLE> <TABLE class=Koma><CAPTION>JavaScript実行:GMTフォーマットにする</CAPTION> <TR><TD><TEXTAREA class=Sou> D=new Date(D).toGMTString() </TEXTAREA><BUTTON class=Btn onclick="JaExDispD(this)">D</BUTTON> </TABLE> <TABLE class=Koma><CAPTION>JavaScript実行:クッキーに登録</CAPTION> <TR><TD><TEXTAREA class=Sou> document.cookie="test=テスト;Expires="+D </TEXTAREA><BUTTON class=Btn onclick="JaExDispD(this)">D</BUTTON> </TABLE> <TABLE class=Koma> <TR><TD>内容<INPUT class=SouI value="document.cookie"><BUTTON class=Btn onclick="DispObjList(this)">表</BUTTON> <DIV class=内容1></DIV> </TABLE> 【実例
//処理:HTMLリファレンス用検索 //編集:2007.04.09 by T.A. //呼出:<SCRIPT type="text/JavaScript" src="Cookie.js"></SCRIPT> // <SCRIPT type="text/JavaScript" src="Kennsaku.js"></SCRIPT> var KenHTML="<INPUT id=DocKenInp style='width:100%; font-family:MS ゴシック'><BR>"+ "<BUTTON id=DocKenKou style='font-size:1ex; width:; height:; line-height:115%' onclick='Kennsaku(1)' title='後方検索。[Alt]+[N]'>▼</BUTTON>"; document.write(KenHTML); var KenStr; //●---------- //処理:初期化検索データ読み込みと設定 //編集:2007.04.09 by 雨宮徹也 //呼出:<BODY onload="KenInit()"> //---------- function KenInit(){ var D; DocKenInp.value=GetCookie("KenStr"); // KenStr=DocKenInp.value; D=GetCookie("KenMojKub"); if(D=="true"){ DocKubetu.status=true; }else{ DocKubetu.status=false; } KenSave(); } //●---------- //処理:検索データの保存 //編集:2007.04.09 by 雨宮徹也 //呼出:KenSave() //---------- function KenSave(){ //手順はKanSave()と同じ。 var FPath=document.URLUnencoded; //「file://C:\My Documents\…\HTMLリファレンス\…」 var St=FPath.indexOf("/"); var En=FPath.lastIndexOf("\\"); En=FPath.lastIndexOf("\\",En-1); var CPath=FPath.substring(St+1,En+1); //「/C:\My Documents\…\HTMLリファレンス\」 //window.status="KanSave:"+Kioku.status; //setTimeout("window.status=''",500); ND=new Date().getTime(); ND=ND+1000*60*60*24*30; //30日間記憶 SetCookie("KenStr",DocKenInp.value,new Date(ND),CPath); SetCookie("KenMojKub",DocKubetu.status,new Date(ND),CPath); } var AN,Dir; function Kennsaku(N){ AN=DocKenInp.value; Dir=N; FindIndexB(); } //●───── //処理:Content文書内検索 //編集:2007.04.09 by T.A. //呼出:変数=FindIndexB(); //必要:<INPUT id=DocKubetu type=checkbox> //説明:A要素のテキストと比較して探す(部分一致)。 //戻値:false=見つからなかった。true=見つかったオブジェクト。 //───── var TxRgObj; function FindIndexB(){ var AN1,AN2,TagCol,I,ND; KenSave(); if(!AN){return false} window.status=""; if(DocKubetu.status){Kubetu=4 }else{Kubetu=0 } SObj=document.selection; if(SObj.type=="Text"){ //範囲選択状態なら… if(TxRgObj){ if(Dir==1){ TxRgObj.move("character",1); }else{ TxRgObj.move("character",-1); } } TxRgObj=SObj.createRange(); if(Dir==1){ TxRgObj.move("character",1); }else{ TxRgObj.move("character",-1); } }else{ //選択されていないなら… if(!TxRgObj){ TxRgObj=document.body.createTextRange(); } } A=TxRgObj.findText(AN,Dir,Kubetu); //検索 if(A){ //見つかった… TxRgObj.select(); A=TxRgObj.text; window.status=A; }else{ TxRgObj=""; window.status="なし"; } } //● //処理:1つのクッキー・データを設定する //編集:2006.09.26 by T.A. //呼出:SetCookie(Name,Value,Expires,Path,Domain,Secure) //引数:Name=クッキー名(半角英数)。 // Value=クッキー・データ(任意の文字列。半角英数~漢字)。 // Expires=クッキーの有効期限(日付)。省くと、期限はブラウザを閉じるまで。 // Path=パス。例="/tetuya630213"など。 // Domain=ドメイン名。例="blog.livedoor.jp"など。 // Secure= true=セキュリティの保たれた環境でなければアクセスできないようにする。←→false。 //例: // var T=new Date(); // var TD=T.getTime()+1000*60*60*24*30; //30日記憶 // var KT=new Date(ND); // SetCookie("テスト値","あいうえお",KT) function SetCookie(Name,Value,Expires,Path,Domain,Secure){ var S=Name+"="+escape(Value) +(Expires?"; expires="+Expires.toGMTString():"") +(Path?"; path="+Path:"") +(Domain?"; domain="+Domain:"") +(Secure?"; secure":""); document.cookie=S; } //● //処理:1つのクッキー・データを得る //編集:2006.10.22 by T.A. //呼出:変数=GetCookie(Name) //引数:Name=クッキー名。省くと全て取得。 function GetCookie(Name){ if(!Name)return unescape(document.cookie); var CNP=Name+"="; var C=document.cookie; var SF=C.indexOf(CNP); if (SF==-1)return ""; //クッキーが見つからない。又はデータが""の為にクッキー名のみになっている。 var SF2=C.indexOf(";",SF+CNP.length); if (SF2==-1)SF2=C.length; //データが1個の場合、「;」は無い。 return unescape(C.substring(SF+CNP.length,SF2)); } //● //処理:1つのクッキー・データを削除する //編集:2006.09.26 by T.A. //呼出:変数=DeleteCookie(Name,Path,Domain) //引数:Name=クッキー名。 // Path=パス。例="/tetuya630213"など。 // Domain=ドメイン名。例="blog.livedoor.jp"など。 function DeleteCookie(Name,Path,Domain){ if(GetCookie(Name))document.cookie=Name+"=" +(Path?"; path="+Path:"") +(Domain?"; domain="+Domain:"") +"; expires="+new Date(0).toGMTString(); //過去の日付 }