Every XML and HTML document in an HTML UA is represented by a
Document object. [DOM3CORE]
Document objects are assumed to be XML documents unless they are flagged as being HTML documents when they are created. Whether a document is
an HTML document or an XML document affects the
behaviour of certain APIs, as well as a few CSS rendering rules. [CSS21]
A Document object created by the createDocument() API on the DOMImplementation
object is initially an XML
document, but can be made into an HTML document by calling document.open() on it.
All Document objects (in user agents implementing this
specification) must also implement the HTMLDocument interface, available using
binding-specific methods. (This is the case whether or not the document in
question is an HTML document
or indeed whether it contains any HTML
elements at all.) Document objects must also implement
the document-level interface of any other namespaces found in the document
that the UA supports. For example, if an HTML implementation also supports
SVG, then the Document object must implement HTMLDocument and SVGDocument.
Because the HTMLDocument interface is now obtained
using binding-specific casting methods instead of simply being the primary
interface of the document object, it is no longer defined as inheriting
from Document.
interface HTMLDocument {
// Resource metadata management
readonly attribute Location location;
readonly attribute DOMString URL;
attribute DOMString domain;
readonly attribute DOMString referrer;
attribute DOMString cookie;
readonly attribute DOMString lastModified;
readonly attribute DOMString compatMode;
// DOM tree accessors
attribute DOMString title;
attribute DOMString dir;
attribute HTMLElement body;
readonly attribute HTMLCollection images;
readonly attribute HTMLCollection links;
readonly attribute HTMLCollection forms;
readonly attribute HTMLCollection anchors;
NodeList getElementsByName(in DOMString elementName);
NodeList getElementsByClassName(in DOMString classNames);
// Dynamic markup insertion
attribute DOMString innerHTML;
HTMLDocument open();
HTMLDocument open(in DOMString type);
HTMLDocument open(in DOMString type, in DOMString replace);
Window open(in DOMString url, in DOMString name, in DOMString features);
Window open(in DOMString url, in DOMString name, in DOMString features, in boolean replace);
void close();
void write(in DOMString text);
void writeln(in DOMString text);
// Interaction
readonly attribute Element activeElement;
readonly attribute boolean hasFocus;
// Commands
readonly attribute HTMLCollection commands;
// Editing
attribute boolean designMode;
boolean execCommand(in DOMString commandId);
boolean execCommand(in DOMString commandId, in boolean doShowUI);
boolean execCommand(in DOMString commandId, in boolean doShowUI, in DOMString value);
Selection getSelection();
};
Since the HTMLDocument
interface holds methods and attributes related to a number of disparate
features, the members of this interface are described in various different
sections.
User agents must raise a security exception
whenever any of the members of an HTMLDocument object are accessed by
scripts whose origin is not the same as the
Document's origin.
The URL attribute
must return the document's address.
The domain
attribute must be initialised to the document's domain, if it
has one, and null otherwise. On getting, the attribute must return its
current value. On setting, if the new value is an allowed value (as
defined below), the attribute's value must be changed to the new value. If
the new value is not an allowed value, then a security exception must be raised instead.
A new value is an allowed value for the document.domain
attribute if it is equal to the attribute's current value, or if the new
value, prefixed by a U+002E FULL STOP ("."), exactly matches the end of
the current value. If the current value is null, new values other than
null will never be allowed.
If the Document object's address is hierarchical and uses a
server-based naming authority, then its domain is the <host>/<ihost> part of that
address. Otherwise, it has no domain.
The domain attribute is used to enable pages on
different hosts of a domain to access each others' DOMs, though this is not yet defined by this
specification.
we should handle IP addresses here
The referrer attribute must
return either the URI of the page which navigated the browsing context
to the current document (if any), or the empty string (if there is no such
originating page, or if the UA has been configured not to report
referrers).
In the case of HTTP, the referrer DOM attribute will match the
Referer (sic) header that was sent when fetching the current
page.
The cookie
attribute must, on getting, return the same string as the value of the
Cookie HTTP header it would include if fetching the
resource indicated by the document's address over HTTP, as
per RFC 2109 section 4.3.4. [RFC2109]
On setting, the cookie attribute must cause the user agent to
act as it would when processing cookies if it had just attempted to fetch
the document's address over HTTP, and had received a response
with a Set-Cookie header whose value was the specified value,
as per RFC 2109 sections 4.3.1, 4.3.2, and 4.3.3. [RFC2109]
Since the cookie attribute is accessible across frames,
the path restrictions on cookies are only a tool to help manage which
cookies are sent to which parts of the site, and are not in any way a
security feature.
The lastModified attribute,
on getting, must return the date and time of the Document's
source file's last modification, in the user's local timezone, in the
following format:
All the numeric components above, other than the year, must be given as two digits in the range U+0030 DIGIT ZERO to U+0039 DIGIT NINE representing the number in base ten, zero-padded if necessary.
The Document's source file's last modification date and
time must be derived from relevant features of the networking protocols
used, e.g. from the value of the HTTP Last-Modified
header of the document, or from metadata in the filesystem for local
files. If the last modification date and time are not known, the attribute
must return the string 01/01/1970 00:00:00.
The compatMode DOM attribute
must return the literal string "CSS1Compat" unless
the document has been set to quirks mode by the HTML parser, in which case it must instead return the
literal string "BackCompat". The document can also
be set to limited quirks mode (also known as "almost
standards" mode). By default, the document is set to no
quirks mode (also known as "standards mode").