DOM において、document オブジェクトは HTML, XHTML, そして XML ドキュメントを表す一般的な方法を提供します。document オブジェクトは一般的な DOM Core document インタフェースを備えています。
一般化された DOM Core document インタフェースに加えて、HTML documents もまた、HTML ドキュメント (例えば、document.cookie, document.alinkColor) の処理に対してより特化されたDOM HTMLDocument インタフェースを備えています。プロパティとメソッドの一覧の一部である、より特化されたインタフェースは、その隣にアスタリスク (*) が付きます。
document は window オブジェクトに含まれ、かなり多くの要素を含んでいます。
document インタフェースは、ドキュメントタイプ、その色と形式、プラグインとアプレットなどへのアクセスを提供します。さらに、すべてのドキュメントの子ノード、または BODY や TABLE のような要素を作成し、操作するメソッドを提供します。
プロパティ
| 名前 | 説明 | 戻り値の型 | 適用 |
|---|---|---|---|
document.activeElement |
現在フォーカス状態にある要素を返す | element |
HTML 5 |
document.alinkColor* |
document body 内のアクティブなリンクの色を取得 / 設定 | String | DOM 0 |
document.all |
HTML 5 | ||
document.anchors* |
document 内のすべてのアンカーのリストを返す | HTMLCollection |
HTML |
document.applets* |
document に含まれるアプレットのリスト (出現順) を返す | HTMLCollection |
HTML |
document.async |
async is used with document.load to indicate an asynchronous request. |
n/a | DOM 3 |
Node.attributes |
指定要素の属性のコレクションを返す | NamedNodeMap | |
Node.baseURI |
文書のベース URI を取得 | String | DOM 3 |
document.baseURIObject |
document の ベース URI を表す nsIURI オブジェクトを返す |
nsIURI |
All |
document.bgColor* |
現在の document の背景色を取得/設定します。 | String | DOM 0 |
document.body* |
現在の document の BODY ノードを返します。 | HTMLBodyElement | HTML |
document.characterSet |
document に使用されている文字セットを返します。 | String | DOM 0 |
Node.childNodes |
指定ノードの子ノードの コレクション を返す | NodeList | |
document.compatMode |
document が Quirks モードと Strict モードのどちらで描画されているかを示す | String | HTML, XHTML |
| 現在の document の MIME ヘッダから Content-Type を返す | String | ||
document.cookie* |
document の cookie のセミコロンで区切られたリストを返すか、一つの cookie を設定します。 | String | HTML |
document.currentScript |
Returns the <script> element that is currently executing. |
Element |
HTML, XUL |
document.defaultView |
window オブジェクトへの参照を返します。 | Window |
DOM 2 View |
document.designMode |
designMode は Midas による WYSYWIG 編集が可能かどうかを取得/設定します。これは HTML ドキュメントにのみ使用することができます。 | String | HTML |
document.dir |
文書の書字方向 (rtl / ltr) の取得 / 設定 | String | |
document.doctype |
現在の document の文書型宣言 (DTD) を返します。 | DocumentType |
DOM 2 Core |
document.documentElement |
document の直接の子である要素を返します。HTML 文書では、これは通常の HTML 要素です。 | Element |
All |
document.documentURI |
文書のロケーションを返す | String | DOM 3 |
document.documentURIObject |
document の URI の代わりとなる nsIURI オブジェクトを返します。このプロパティだけは特権 (UniversalXPConnect 特権) を持った JavsScript コード 内で特別な意味を持ちます。 |
nsIURI | |
document.domain* |
現在の document のドメインを返す | String | HTML |
document.domConfig |
Should return a DOMConfiguration object | DOMConfiguration | DOM 3 |
document.embeds |
現在の document に含まれる埋め込まれた OBJECTS のリストを返します。 | HTMLCollection |
DOM 0 |
document.fgColor* |
現在の document の前景色または文字色を取得/設定します。 | String | DOM 0 |
document.fileSize |
document または img 要素のファイルサイズを返す | Number | IE ext. |
Node.firstChild |
document の直接の子のリスト内の最初のノードを返します。 | DocumentType | DOM 2 Core |
document.forms* |
現在の document 内の FORM 要素のリストを返す | HTMLCollection |
HTML |
document.height |
現在の document の高さを取得 / 設定 | Number | DOM 0 |
document.images* |
現在の document の画像のリストを返す | HTMLCollection |
HTML |
document.implementation |
現在の document に関連付けられた DOM 実装を返します。 | DOMImplementation |
DOM 2 Core |
document.inputEncoding |
document のパース時のエンコーディングを返す | String | DOM 3 |
Node.lastChild |
ノード内の最後の子ノードを返す | Node | |
document.lastModified |
document の最終更新日を返す | String | DOM 0 |
document.lastStyleSheetSet |
Returns the name of the style sheet set that was last enabled. Has the value null until the style sheet is changed by setting the value of selectedStyleSheetSet. |
String | |
document.linkColor* |
document 内のハイパーリンクの色を取得 / 設定 | String | DOM 0 |
document.links* |
document 内のすべてのハイパーリンクのリストを返す | HTMLCollection |
HTML |
Node.localName |
Returns the local part of the qualified name of this node (null for a document) | String | |
document.location |
現在の document の URI を返します。 | Location |
DOM 0 |
Node.namespaceURI |
現在の document の XML 名前空間を返します。 | All | |
Node.nextSibling |
Returns the node immediately following the specified one in its parent's childNodes list, or null if the specified node is the last node in that list (null for documents) | ||
Node.nodeName |
Returns the node's name (#document for document) | String | |
Node.nodeType |
ノードタイプ定数を返す(※ document.nodeType は 9 を返す) |
Number | |
Node.nodeValue |
ノードの値を返す (※ document.nodeValue は null を返す) |
||
Node.nodePrincipal |
document の セキュリティコンテキストを表す nsIPrincipal オブジェクトを返します。 |
nsIPrincipal |
All |
Node.ownerDocument |
指定ノードのトップレベルの document オブジェクトを返す(指定ノードがトップレベルであった場合、null が返る) | ||
Node.parentNode |
Returns the parent of the specified node in the DOM tree (null for document) | ||
document.plugins |
利用可能なプラグインのリストを返します。 | HTMLCollection |
DOM 0 |
document.popupNode |
popup が起こされたノードを返します (XML ドキュメントのみ)。 |
Node | XUL |
document.preferredStyleSheetSet |
Returns the preferred style sheet set as specified by the page author. | String | |
Node.prefix |
Returns the namespace prefix of the specified node, or null if no prefix is specified |
||
Node.previousSibling |
Returns the node immediately preceding the specified one in its parent's childNodes list, null if the specified node is the first in that list (null for document) |
||
document.readyState |
文書の読み込み状況を表す文字列を返す | String | HTML5 |
document.referrer* |
このページへリンクしたページの URI を返します。 | String | HTML |
document.selectedStyleSheetSet |
Returns which style sheet set is currently in use. | String | |
document.strictErrorChecking |
Returns true if error checking is enforced or false if it is not. |
Boolean | DOM 3 |
document.styleSheets |
現在の document の stylesheet オブジェクトのリストを返します。 |
StyleSheetList |
DOM 2 Style |
document.styleSheetSets |
Returns a list of the style sheet sets available on the document. | StringList | |
Node.textContent |
Returns null (returns other values for other nodes). | Null | DOM 3 |
document.title* |
現在の document のタイトルを返します。 | String | HTML |
document.tooltipNode |
現在の tooltip のターゲットノードを返します。 |
Node Object | XUL |
document.URL* |
現在の document の URL を含む文字列を返します。 | String | HTML |
document.vlinkColor* |
訪問済みのハイパーリンクの色を取得/設定します。 | String | DOM 0 |
document.width |
現在の document の幅を返します。 | Number | DOM 0 |
document.xmlEncoding |
Returns the encoding as determined by the XML declaration. | String | DOM 3 |
document.xmlStandalone |
Returns true if the XML declaration specifies the document is standalone (e.g., An external part of the DTD affects the document's content), else false. |
Boolean | DOM 3 |
document.xmlVersion |
Returns the version number as specified in the XML declaration or "1.0" if the declaration is absent. |
String | DOM 3 |
メソッド
-
element.addEventListener - Adds an event listener to the document.
-
document.adoptNode - Adopt node from an external document
-
Node.appendChild - Adds a node to the end of the list of children of a specified parent node.
-
document.captureEvents - ---
-
document.caretPositionFromPoint -
Gets a
CaretPositionbased on two coordinates. -
document.clear* - In majority of modern browsers, including recent versions of Firefox and Internet Explorer, this method does nothing.
-
Node.cloneNode - Makes a copy of a node or document
-
document.close* - Closes a document stream for writing.
-
Node.compareDocumentPosition - Compares the position of the current node against another node in any other document.
-
document.createAttribute - Creates a new attribute node and returns it.
-
document.createAttributeNS - Creates a new attribute node in a given namespace and returns it.
-
document.createCDATASection - Creates a new CDATA node and returns it.
-
document.createComment - Creates a new comment node and returns it.
-
document.createDocumentFragment - Creates a new document fragment.
-
document.createElement - Creates a new element with the given tag name.
-
document.createElementNS - Creates a new element with the given tag name and namespace URI.
-
document.createEntityReference廃止 Gecko 7.0 - Creates a new entity reference object and returns it.
-
document.createEvent - Creates an event.
-
document.createExpression -
Compiles an
XPathExpressionwhich can then be used for (repeated) evaluations. -
document.createNSResolver - Creates an XPathNSResolver.
-
document.createProcessingInstruction - Creates a new processing instruction element and returns it.
-
document.createRange -
Rangeオブジェクトを生成 -
document.createTextNode - テキストノードを生成
-
document.createTreeWalker -
treeWalkerオブジェクトを生成 -
document.elementFromPoint - Returns the element visible at the specified coordinates.
-
document.enableStyleSheetsForSet() - Enables the style sheets for the specified style sheet set.
-
document.evaluate - Evaluates an XPath expression.
- document.execCommand*
- Executes a Midas command.
-
document.execCommandShowHelp廃止 Gecko 14.0 - This method never did anything and always threw an exception, so it was removed in Gecko 14.0 (Firefox 14.0 / Thunderbird 14.0 / SeaMonkey 2.11)
-
document.getBoxObjectFor - Returns a boxObject (x, y, width, height) for a specified element.
-
document.getElementById - 特定のidを持つエレメントへのオブジェクト参照を返します.
-
document.getElementsByClassName - (引数で)与えられたclass名を持つエレメント群のリストを返します.
-
document.getElementsByName* - (引数で)与えられた名前(name)を持つエレメント群のリストを返します.
-
document.getElementsByTagName - (引数で)与えられたタグ名(tag name)を持つエレメント群のリストを返します.
-
document.getElementsByTagNameNS - (引数で)与えられたタグ名(tag name)と名前空間(namespase)を持つエレメント群のリストを返します.
-
Node.getFeature - ---
-
document.getSelection -
Returns a
Selectionobject related to text selected in the document. -
Node.getUserData - Returns any data previously set on the node via setUserData() by key
-
Node.hasAttributes - Indicates whether the node possesses attributes
-
Node.hasChildNodes - Returns a Boolean value indicating whether the current element has child nodes or not.
-
document.hasFocus -
Returns
trueif the focus is currently located anywhere inside the specified document. -
document.importNode - Returns a clone of a node from an external document
-
Node.insertBefore - Inserts the specified node before a reference node as a child of the current node.
-
Node.isDefaultNamespace - Returns true if the namespace is the default namespace on the given node
-
Node.isEqualNode - Indicates whether the node is equal to the given node
-
Node.isSameNode - Indicates whether the node is the same as the given node
-
Node.isSupported - Tests whether the DOM implementation implements a specific feature and that feature is supported by this node or document
-
document.load - Load an XML document
-
document.loadOverlay* - Loads a XUL overlay dynamically. This only works in XUL documents.
-
Node.lookupNamespaceURI - Returns the namespaceURI associated with a given prefix on the given node object
-
Node.lookupPrefix - Returns the prefix for a given namespaceURI on the given node if present
-
Node.normalize - Normalizes the node or document
-
document.normalizeDocument廃止 Gecko 7.0 - Replaces entities, normalizes text nodes, etc.
-
document.open* - Opens a document stream for writing.
-
document.queryCommandEnabled* - Returns true if the Midas command can be executed on the current range.
-
document.queryCommandIndeterm* - Returns true if the Midas command is in a indeterminate state on the current range.
-
document.queryCommandState* - Returns true if the Midas command has been executed on the current range.
-
document.queryCommandSupported - ---
-
document.queryCommandText廃止 Gecko 14.0 - This method never did anything but throw an exception, and was removed in Gecko 14.0 (Firefox 14.0 / Thunderbird 14.0 / SeaMonkey 2.11).
-
document.queryCommandValue* - Returns the current value of the current range for Midas command. As of Firefox 2.0.0.2, queryCommandValue will return an empty string when a command value has not been explicitly set.
-
document.querySelector - Returns the first Element node within the document, in document order, that matches the specified selectors.
-
document.querySelectorAll - Returns a list of all the Element nodes within the document that match the specified selectors.
-
document.releaseCapture() - Releases the current mouse capture if it's on an element in this document.
-
document.releaseEvents -
Node.removeChild - Removes a child node from the DOM
-
document.removeEventListener - Removes an event listener from the document
-
Node.replaceChild - Replaces one child node of the specified node with another
-
document.routeEvent - ---
-
document.mozSetImageElement - Allows you to change the element being used as the background image for a specified element ID.
-
Node.setUserData - Attaches arbitrary data to a node, along with a user-defined key and an optional handler to be triggered upon events such as cloning of the node upon which the data was attached
-
document.write* - Writes text to a document.
-
document.writeln* - Write a line of text to a document.
イベントハンドラ
Firefox 3 introduces two new events: "online" and "offline". These two events are fired on the <body> of each page when the browser switches between online and offline mode. Additionally, the events bubble up from document.body, to document, ending at window. Both events are non-cancellable (you can't prevent the user from coming online, or going offline). For more info see Online_and_offline_events.
-
document.ononline -
Returns the event handling code for the
onlineevent. -
document.onoffline -
Returns the event handling code for the
offlineevent. -
document.onreadystatechange -
Returns the event handling code for the
readystatechangeevent.
Starting in Gecko 9.0 (Firefox 9.0 / Thunderbird 9.0 / SeaMonkey 2.6), you can now use the syntax if ("onabort" in document) to determine whether or not a given event handler property exists. This is because event handler interfaces have been updated to be proper web IDL interfaces. See DOM event handlers for details.
Security notes
This section covers security improvements made in Firefox 3/Gecko 1.9.
When a new document is created, it initially gets "about:blank" loaded into it. In versions of Firefox prior to Firefox 3, "about:blank" documents didn't get the parent principal. This means that access to their contents was not restricted. While this doesn't seem like a significant issue, it can be if code proceeds to add content to the document using DOM methods and properties such as Node.appendChild and so forth, because that content would not be protected from unauthorized access.
Firefox 3 updates Gecko so that new documents inherit the parent principal. This improves security both for iframes and documents that are in the process of being loaded, as well as for documents constructed programmatically.