This is revision 1.5612.
Every XML and HTML document in an HTML UA is represented by a
Document
object. [DOMCORE]
The document's address is an absolute URL
that is set when the Document
is created. The
document's current address is an absolute URL
that can change during the lifetime of the Document
,
for example when the user navigates to
a fragment identifier on the
page or when the pushState()
method is called
with a new URL. The document's
current address must be set to the document's
address when the Document
is created.
Interactive user agents typically expose the document's current address in their user interface.
When a Document
is created by a script using the createDocument()
or createHTMLDocument()
APIs, the document's address is the same as the
document's address of the script's document, and
the Document
is both ready for post-load
tasks and completely loaded immediately.
Each Document
object has a reload override
flag that is originally unset. The flag is set by the document.open()
and document.write()
methods in certain
situations. When the flag is set, the Document
also has
a reload override buffer which is a Unicode string that
is used as the source of the document when it is reloaded.
When the user agent is to perform an overridden reload, it must act as follows:
Let source be the value of the browsing context's active document's reload override buffer.
Navigate the
browsing context to a resource whose source is source, with replacement enabled. When
the navigate algorithm creates a Document
object for this purpose, set that Document
's
reload override flag and set its reload override
buffer to source.
The DOM Core specification defines a Document
interface, which this specification
extends significantly:
[OverrideBuiltins] partial interface Document { // resource metadata management [PutForwards=href] 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 readyState; // DOM tree accessors getter object (DOMString name); attribute DOMString title; attribute DOMString dir; attribute HTMLElement? body; readonly attribute HTMLHeadElement? head; readonly attribute HTMLCollection images; readonly attribute HTMLCollection embeds; readonly attribute HTMLCollection plugins; readonly attribute HTMLCollection links; readonly attribute HTMLCollection forms; readonly attribute HTMLCollection scripts; NodeList getElementsByName(DOMString elementName); // dynamic markup insertion Document open(optional DOMString type, optional DOMString replace); WindowProxy open(DOMString url, DOMString name, DOMString features, optional boolean replace); void close(); void write(DOMString... text); void writeln(DOMString... text); // user interaction readonly attribute WindowProxy? defaultView; readonly attribute Element? activeElement; boolean hasFocus(); attribute DOMString designMode; boolean execCommand(DOMString commandId); boolean execCommand(DOMString commandId, boolean showUI); boolean execCommand(DOMString commandId, boolean showUI, DOMString value); boolean queryCommandEnabled(DOMString commandId); boolean queryCommandIndeterm(DOMString commandId); boolean queryCommandState(DOMString commandId); boolean queryCommandSupported(DOMString commandId); DOMString queryCommandValue(DOMString commandId); readonly attribute HTMLCollection commands; // event handler IDL attributes [TreatNonCallableAsNull] attribute Function? onabort; [TreatNonCallableAsNull] attribute Function? onblur; [TreatNonCallableAsNull] attribute Function? oncanplay; [TreatNonCallableAsNull] attribute Function? oncanplaythrough; [TreatNonCallableAsNull] attribute Function? onchange; [TreatNonCallableAsNull] attribute Function? onclick; [TreatNonCallableAsNull] attribute Function? oncontextmenu; [TreatNonCallableAsNull] attribute Function? oncuechange; [TreatNonCallableAsNull] attribute Function? ondblclick; [TreatNonCallableAsNull] attribute Function? ondrag; [TreatNonCallableAsNull] attribute Function? ondragend; [TreatNonCallableAsNull] attribute Function? ondragenter; [TreatNonCallableAsNull] attribute Function? ondragleave; [TreatNonCallableAsNull] attribute Function? ondragover; [TreatNonCallableAsNull] attribute Function? ondragstart; [TreatNonCallableAsNull] attribute Function? ondrop; [TreatNonCallableAsNull] attribute Function? ondurationchange; [TreatNonCallableAsNull] attribute Function? onemptied; [TreatNonCallableAsNull] attribute Function? onended; [TreatNonCallableAsNull] attribute Function? onerror; [TreatNonCallableAsNull] attribute Function? onfocus; [TreatNonCallableAsNull] attribute Function? oninput; [TreatNonCallableAsNull] attribute Function? oninvalid; [TreatNonCallableAsNull] attribute Function? onkeydown; [TreatNonCallableAsNull] attribute Function? onkeypress; [TreatNonCallableAsNull] attribute Function? onkeyup; [TreatNonCallableAsNull] attribute Function? onload; [TreatNonCallableAsNull] attribute Function? onloadeddata; [TreatNonCallableAsNull] attribute Function? onloadedmetadata; [TreatNonCallableAsNull] attribute Function? onloadstart; [TreatNonCallableAsNull] attribute Function? onmousedown; [TreatNonCallableAsNull] attribute Function? onmousemove; [TreatNonCallableAsNull] attribute Function? onmouseout; [TreatNonCallableAsNull] attribute Function? onmouseover; [TreatNonCallableAsNull] attribute Function? onmouseup; [TreatNonCallableAsNull] attribute Function? onmousewheel; [TreatNonCallableAsNull] attribute Function? onpause; [TreatNonCallableAsNull] attribute Function? onplay; [TreatNonCallableAsNull] attribute Function? onplaying; [TreatNonCallableAsNull] attribute Function? onprogress; [TreatNonCallableAsNull] attribute Function? onratechange; [TreatNonCallableAsNull] attribute Function? onreset; [TreatNonCallableAsNull] attribute Function? onscroll; [TreatNonCallableAsNull] attribute Function? onseeked; [TreatNonCallableAsNull] attribute Function? onseeking; [TreatNonCallableAsNull] attribute Function? onselect; [TreatNonCallableAsNull] attribute Function? onshow; [TreatNonCallableAsNull] attribute Function? onstalled; [TreatNonCallableAsNull] attribute Function? onsubmit; [TreatNonCallableAsNull] attribute Function? onsuspend; [TreatNonCallableAsNull] attribute Function? ontimeupdate; [TreatNonCallableAsNull] attribute Function? onvolumechange; [TreatNonCallableAsNull] attribute Function? onwaiting; // special event handler IDL attributes that only apply to Document objects [TreatNonCallableAsNull,LenientThis] attribute Function? onreadystatechange; };
User agents must throw a
SecurityError
exception whenever any properties of a
Document
object are accessed by scripts whose
effective script origin is not the same as the Document
's effective
script origin.
URL
Returns the document's address.
referrer
Returns the
address of the Document
from which the user
navigated to this one, unless it was blocked or there was no such
document, in which case it returns the empty string.
The noreferrer
link
type can be used to block the referrer.
The URL
attribute must return the document's address.
The referrer
attribute
must return either the current address of the active document
of the source browsing context at the time the
navigation was started (that is, the page which navigated the browsing context
to the current document), with any <fragment> component removed; or
the empty string if there is no such originating page, or if the UA
has been configured not to report referrers in this case, or if the
navigation was initiated for a hyperlink with a noreferrer
keyword.
In the case of HTTP, the referrer
IDL attribute will
match the Referer
(sic) header
that was sent when fetching the current
page.
Typically user agents are configured to not report
referrers in the case where the referrer uses an encrypted protocol
and the current page does not (e.g. when navigating from an https:
page to an http:
page).
cookie
[ = value ]Returns the HTTP cookies that apply to the
Document
. If there are no cookies or cookies can't be
applied to this resource, the empty string will be returned.
Can be set, to add a new cookie to the element's set of HTTP cookies.
If the contents are sandboxed into a unique origin (in an
iframe
with the sandbox
attribute), a
SecurityError
exception will be thrown on getting and
setting.
The cookie
attribute represents the cookies of the resource from which the
Document
was created.
A Document
object that falls into one of the
following conditions is a cookie-free Document
object:
Document
that has no browsing
context.Document
whose address does not use a server-based naming
authority.On getting, if the document is a
cookie-free Document
object, then the user
agent must return the empty string. Otherwise, if the
Document
's origin is not a
scheme/host/port tuple, the user agent must throw a
SecurityError
exception. Otherwise, the user agent must
first obtain the storage mutex and then return the
cookie-string for the document's address for a
"non-HTTP" API, decoded as UTF-8, with error handling.
[COOKIES]
On setting, if the document is a cookie-free
Document
object, then the user agent must do
nothing. Otherwise, if the Document
's
origin is not a scheme/host/port tuple, the user agent
must throw a SecurityError
exception. Otherwise, the
user agent must obtain the storage mutex and then act
as it would when receiving a set-cookie-string for
the document's address via a "non-HTTP" API, consisting
of the new value encoded as UTF-8. [COOKIES] [RFC3629]
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.
lastModified
Returns the date of the last modification to the document, as
reported by the server, in the form "MM/DD/YYYY hh:mm:ss
", in the user's local
time zone.
If the last modification date is not known, the current time is returned instead.
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 time zone, in the following format:
All the numeric components above, other than the year, must be given as two digits in the range ASCII digits representing the number in base ten, zero-padded if necessary. The year must be given as the shortest possible string of four or more digits in the range ASCII digits 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 file system for local files. If
the last modification date and time are not known, the attribute
must return the current date and time in the above format.
readyState
Returns "loading
" while the Document
is loading, "interactive
" once it is finished parsing but still loading sub-resources, and "complete
" once it has loaded.
The readystatechange
event fires on the Document
object when this value changes.
Each document has a current document readiness. When a
Document
object is created, it must have its
current document readiness set to the string "loading
"
if the document is associated with an HTML parser or an
XML parser, or to the string "complete
" otherwise.
Various algorithms during page loading affect this value. When the
value is set, the user agent must fire a simple event
named readystatechange
at the Document
object.
A Document
is said to have an active
parser if it is associated with an HTML parser or
an XML parser that has not yet been stopped or aborted.
The readyState
IDL
attribute must, on getting, return the current document
readiness.
The html
element of a document is the
document's root element, if there is one and it's an
html
element, or null otherwise.
head
Returns the head
element.
The head
element of a document is the
first head
element that is a child of the
html
element, if there is one, or null
otherwise.
The head
attribute, on getting, must return the head
element of the document (a head
element or
null).
title
[ = value ]Returns the document's title, as given by the
title
element.
Can be set, to update the document's title. If there is no
head
element,
the new value is ignored.
In SVG documents, the SVGDocument
interface's
title
attribute takes
precedence.
The title
element of a document is the
first title
element in the document (in tree order), if
there is one, or null otherwise.
The title
attribute must,
on getting, run the following algorithm:
If the root element is an svg
element in the "http://www.w3.org/2000/svg
"
namespace, and the user agent supports SVG, then return the value
that would have been returned by the IDL attribute of the same name
on the SVGDocument
interface. [SVG]
Otherwise, let value be a concatenation
of the data of all the child Text
nodes of the
title
element, in tree order, or
the empty string if the title
element is
null.
Replace any sequence of one or more consecutive space characters in value with a single U+0020 SPACE character.
Strip leading and trailing whitespace from value.
Return value.
On setting, the following algorithm must be run. Mutation events must be fired as appropriate.
If the root element is an svg
element in the "http://www.w3.org/2000/svg
"
namespace, and the user agent supports SVG, then the setter must
act as if it was the setter for the IDL attribute of the same name
on the Document
interface defined by the SVG
specification. Stop the algorithm here. [SVG]
title
element is null and
the head
element is null, then the
attribute must do nothing. Stop the algorithm here.title
element is null, then a
new title
element must be created and appended to
the head
element. Let element be that element. Otherwise, let element be the title
element.Text
node whose data is the new value
being assigned must be appended to element.The title
IDL attribute
defined above must replace the attribute of the same name on the
Document
interface defined by the SVG specification
when the user agent supports both HTML and SVG. [SVG]
body
[ = value ]Returns the body element.
Can be set, to replace the body element.
If the new value is not a body
or frameset
element, this will throw a HierarchyRequestError
exception.
The body element of a document is the first child of
the html
element that is either a
body
element or a frameset
element. If
there is no such element, it is null.
The body
attribute, on getting, must return the body element of
the document (either a body
element, a
frameset
element, or null). On setting, the following
algorithm must be run:
body
or
frameset
element, then throw a
HierarchyRequestError
exception and abort these
steps.replaceChild()
method had been
called with the new value and the
incumbent body element as its two arguments respectively,
then abort these steps.images
Returns an HTMLCollection
of the img
elements in the Document
.
embeds
plugins
Return an HTMLCollection
of the embed
elements in the Document
.
links
Returns an HTMLCollection
of the a
and area
elements in the Document
that have href
attributes.
forms
Return an HTMLCollection
of the form
elements in the Document
.
scripts
Return an HTMLCollection
of the script
elements in the Document
.
The images
attribute must return an HTMLCollection
rooted at the
Document
node, whose filter matches only
img
elements.
The embeds
attribute must return an HTMLCollection
rooted at the
Document
node, whose filter matches only
embed
elements.
The plugins
attribute must return the same object as that returned by the embeds
attribute.
The links
attribute must return an HTMLCollection
rooted at the
Document
node, whose filter matches only a
elements with href
attributes and area
elements with href
attributes.
The forms
attribute must return an HTMLCollection
rooted at the
Document
node, whose filter matches only
form
elements.
The scripts
attribute must return an HTMLCollection
rooted at the
Document
node, whose filter matches only
script
elements.
getElementsByName
(name)Returns a NodeList
of elements in the
Document
that have a name
attribute with the value name.
The getElementsByName(name)
method takes a string name, and must return a live
NodeList
containing all the HTML elements
in that document that have a name
attribute
whose value is equal to the name argument (in a
case-sensitive manner), in tree order.
When the method is invoked on a Document
object again
with the same argument, the user agent may return the same as the
object returned by the earlier call. In other cases, a new
NodeList
object must be returned.
The Document
interface supports named
properties. The supported property names at any
moment consist of the values of the name
content attributes of all the
applet
,
exposed embed
,
form
,
iframe
,
img
, and
exposed object
elements in the Document
that have name
content attributes, and the values of
the id
content attributes of all the
applet
and
exposed object
elements in the Document
that have id
content attributes, and the values of the
id
content attributes of all the
img
elements in the Document
that have both name
content attributes and id
content attributes.
To determine the value of a named property name when the
Document
object is indexed for property
retrieval, the user agent must return the value obtained using
the following steps:
Let elements be the list of named elements with
the name name in the Document
.
There will be at least one such element, by definition.
If elements has only one element, and that
element is an iframe
element, then return the
WindowProxy
object of the nested browsing
context represented by that iframe
element,
and abort these steps.
Otherwise, if elements has only one element, return that element and abort these steps.
Otherwise return an HTMLCollection
rooted at the
Document
node, whose filter matches only named elements with
the name name.
Named elements with the name name, for the purposes of the above algorithm, are those that are either:
applet
, exposed embed
,
form
, iframe
, img
, or
exposed object
elements that have a name
content attribute whose value is name, orapplet
or exposed object
elements that have an id
content
attribute whose value is name, orimg
elements that have an id
content attribute whose value is name, and that have a name
content attribute present also.An embed
or object
element is said to
be exposed if it has no exposed
object
ancestor, and, for object
elements,
is additionally either not showing its fallback content
or has no object
or embed
descendants.
The dir
attribute on the Document
interface is defined
along with the dir
content
attribute.
partial interface XMLDocument { boolean load(DOMString url); };
The load(url)
method must run the following
steps:
Let document be the XMLDocument
object on which the method was invoked.
Resolve the method's
first argument, relative to the entry script's base URL. If this is not
successful, throw a SyntaxError
exception and abort
these steps. Otherwise, let url be the
resulting absolute URL.
If the origin of url is not
the same as the origin of document, throw a SecurityError
exception and abort these steps.
Remove all child nodes of document, without firing any mutation events.
Set the current document readiness of document to "loading
".
Run the remainder of these steps asynchronously, and return true from the method.
Let result be a Document
object.
Let success be false.
Fetch url from the origin of document, with the synchronous flag set and the force same-origin flag set.
If the fetch attempt was successful, and the resource's Content-Type metadata is an XML MIME type, then run these substeps:
Create a new XML parser associated with the result document.
Pass this parser the fetched document.
If there is an XML well-formedness or XML namespace well-formedness error, then remove all child nodes from result. Otherwise let success be true.
Queue a task to run the following steps.
Set the current document readiness of document to "complete
".
Replace all the children of document
by the children of result (even if it has no
children), firing mutation events as if a
DocumentFragment
containing the new children had
been inserted.
Fire a simple event named load
at document.