DOM:document
From MDC
In the DOM, the document object provides a general way to represent HTML, XHTML, and XML documents. Document objects implement the general DOM Core document interface.
In addition to the generalized DOM Core document interface, HTML documents also implement the DOM HTMLDocument interface, which is a more specialized interface for dealing with HTML documents (e.g., document.cookie, document.alinkColor). Properties and methods listed here that are part of this more specialized interface have an asterisk (*) next to them.
The document is contained by the window object and may contain any number of elements.
The document interface provides access to things such as the document type, its color and formatting, plugins and applets, as well providing methods for creating and manipulating all of the document's child nodes, or elements, such as BODY and TABLE elements.
Contents |
[edit] Properties
- document.alinkColor* Deprecated
- Returns or sets the color of active links in the document body.
- document.anchors*
- anchors returns a list of all of the anchors in the document.
- document.applets*
- applets returns an ordered list of the applets within a document.
- document.baseURIObject New in Firefox 3
- baseURIObject returns an
nsIURIobject representing the base URI for the document.
- document.bgColor* Deprecated
- bgColor gets/sets the background color of the current document.
- document.body*
- body returns the BODY node of the current document.
- document.characterSet
- Returns the character set being used by the document.
- document.compatMode*
- Indicates whether the document is rendered in Quirks or Strict mode.
- document.contentType
- Returns the Content-Type from the MIME Header of the current document.
- document.cookie*
- Returns a semicolon-separated list of the cookies for that document or sets a single cookie.
- document.defaultView
- Returns a reference to the window object.
- document.designMode*
- designMode gets/sets WYSYWIG editing capability of Midas. It can only be used for HTML documents.
- document.doctype
- Returns the Document Type Definition (DTD) of the current document.
- document.documentElement
- Returns the Element that is a direct child of document. For HTML documents, this is normally the HTML element.
- document.documentURIObject New in Firefox 3
- Returns the
nsIURIobject representing the URI of the document. This property only has special meaning in privileged JavaScript code (with UniversalXPConnect privileges).
- document.domain*
- domain returns the domain of the current document.
- document.embeds*
- embeds returns a list of the embedded OBJECTS within the current document.
- document.fgColor* Deprecated
- fgColor gets/sets the foreground color, or text color, of the current document.
- document.firstChild
- firstChild returns the first node in the list of direct children of the document. (See also firstChild for the general element property.)
- document.forms*
- forms returns a list of the FORM elements within the current document.
- document.height*
- height gets/sets the height of the current document.
- document.images*
- images returns a list of the images in the current document.
- document.implementation*
- Returns the DOM implementation associated with the current document.
- document.lastModified*
- Returns the date on which the document was last modified.
- document.linkColor* Deprecated
- Gets/sets the color of hyperlinks in the document.
- document.links*
- Returns a list of all the hyperlinks in the document.
- document.location*
- Returns the URI of the current document.
- document.namespaceURI
- Returns the XML namespace of the current document.
- document.nodePrincipal New in Firefox 3
- Returns the
nsIPrincipalobject representing current security context of the document.
- document.plugins*
- Returns a list of the available plugins.
- document.popupNode
- Returns the node upon which a popup was invoked (XUL documents only).
- document.referrer*
- Returns the URI of the page that linked to this page.
- document.styleSheets*
- Returns a list of the stylesheet objects on the current document.
- document.title*
- Returns the title of the current document.
- document.tooltipNode
- Returns the node which is the target of the current tooltip.
- document.URL
- Returns a string containing the URL of the current document.
- document.vlinkColor* Deprecated
- Gets/sets the color of visited hyperlinks.
- document.width*
- Returns the width of the current document.
[edit] Methods
- document.clear* Deprecated
- In majority of modern browsers, including recent versions of Firefox and Internet Explorer, this method does nothing.
- document.close*
- Closes a document stream for writing.
- document.createAttribute
- Creates a new attribute node 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
- Creates a new entity reference object and returns it.
- document.createEvent
- Creates an event.
- document.createNSResolver
- Creates an XPathNSResolver.
- document.createProcessingInstruction
- Creates a new processing instruction element and returns it.
- document.createRange
- Creates a Range object.
- document.createTextNode
- Creates a text node.
- document.createTreeWalker
- Creates a
TreeWalkerobject.
- document.elementFromPoint New in Firefox 3
- Returns the element visible at the specified coordinates.
- document.evaluate
- Evaluates an XPath expression.
- document.execCommand*
- Executes a Midas command.
- document.getElementById
- Returns an object reference to the identified element.
- document.getElementsByClassName New in Firefox 3
- Returns a list of elements with the given class name.
- document.getElementsByName
- Returns a list of elements with the given name.
- document.getElementsByTagName
- Returns a list of elements with the given tag name.
- document.getElementsByTagNameNS
- Returns a list of elements with the given tag name and namespace.
- document.importNode
- Returns a clone of a node from an external document.
- document.loadOverlay New in Firefox 1.5
- Loads a XUL overlay dynamically. This only works in XUL documents.
- 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.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.write*
- Writes text to a document.
- document.writeln*
- Write a line of text to a document.
[edit] Event handlers
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-cancelable (you can't prevent the user from coming online, or going offline). For more info see Online and offline events.
- document.ononline New in Firefox 3
- Returns the event handling code for the online event.
- document.onoffline New in Firefox 3
- Returns the event handling code for the offline event.
[edit] 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 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.