Copyright ©2006 W3C® (MIT, ERCIM, Keio), All Rights Reserved. W3C liability, trademark and document use rules apply.
This specification defines the Window
object, which
provides the global namespace for web scripting languages,
access to other documents in a compound document by reference,
navigation to other locations, and timers. The Window
object is a
long-standing de facto standard for HTML user agents. However,
it should not be assumed based on this or the name "Window"
that it is limited to HTML or to visual user agents.
This section describes the status of this document at the time of its publication. Other documents may supersede this document. A list of current W3C publications and the latest revision of this technical report can be found in the W3C technical reports index at http://www.w3.org/TR/.
This is the 05 April 2006 Working Draft of the Window Object, the first publication of this specification. This document is produced by the Web API WG, part of the Rich Web Clients Activity in the W3C Interaction Domain. The authors of this document are the members of the W3C Web API Working Group.
Web content and browser developers are encouraged to review this draft. Please send comments to public-webapi@w3.org, the W3C's public email list for issues related to Web APIs. Archives of the list are available.
This document was produced by a group operating under the 5 February 2004 W3C Patent Policy. W3C maintains a public list of any patent disclosures made in connection with the deliverables of the group; that page also includes instructions for disclosing a patent. An individual who has actual knowledge of a patent which the individual believes contains Essential Claim(s) must disclose the information in accordance with section 6 of the W3C Patent Policy.
Publication as a Working Draft does not imply endorsement by the W3C Membership. This is a draft document and may be updated, replaced or obsoleted by other documents at any time. It is inappropriate to cite this document as other than work in progress.
This section is not normative.
The Window Object 1.0 specification defines
a subset of the features of the Window
object, a widely
implemented part of HTML User Agents, with parts also found in
non-HTML UAs that offer scripting and DOM access. This
specification is intended to be suitable for all
implementations that present any sort of DOM document
[DOM3Core]
to the user.
This specification defines four features of the window object. It describes the use of the Window object as a browsing context: a container that displays a document, or a series of documents in sequence. It describes interfaces for navigation, the ability to go to a new document in the same browsing context. It describes interfaces for embedding, a feature also known as compound document by reference, where one document includes another separate document by external reference. And it specifies methods for using timers.
In addition, for some languages, such as ECMAScript
[ECMAScript], the Window
interface is
implemented by the object that provides the global namespace
for script execution. The details of how this works for
ECMAScript are specified in ECMAScript Language Binding
Appendix.
This section is not normative.
This section is not normative.
This specification does not include the following features, which are also found on the Window object in some implementations. It is possible they will defined by other specifications or found in a future version of this specification.
This section is not normative.
This specification distinctively marks terms being defined, and references to definitions. Uses of terms are hyperlinks to the point of definition. An example of a definition:
An example of use:
The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in RFC 2119 [RFC2119].
Sometimes, for readability, conformance requirements are phrased as requirements on elements, attributes, methods, interfaces, properties or functions. In all cases these are conformance requirements on implementations.
This specification defines three classes of conformance:
A browsing context is a place where a user agent presents a document or a sequence of documents to the user, using one or more views. Only one document of this sequence is presented at a time. A browsing context is said to navigate when it changes from presenting one document to another, for example by following a hyperlink. More is specified about navigation behavior in the Navigation section.
A visual user agent typically presents a document by rendering it to a display. However, even non-visual agents could have a browsing context. For example, a voice browser also presents documents to the user. This also establishes a browsing context.
An object that implements the Document
interface [DOM3Core] and is presented in a browsing context
MUST also implement the
DocumentWindow
interface.
Each view of a Document
presented in a
browsing
context MUST be represented by an
object that implements the Window
interface. One
of these is the default view.
The default view
is typically the primary mode of presentation to the user, and
in interactive user agents, the primary means of interaction
for the user.
An object that implements the Window
interface is
referred to as a Window
object. Note:
despite the name, a Window
object does not
necessarily represent an onscreen overlapping window, even in
visual user agents.
A document presented in a browsing context may have elements that embed additional documents, forming a Compound Document by Reference. Each such element creates a nested browsing context. This mechanism is described in Embedding: Compound Documents by Reference.
When an event implementing the UIEvent
interface [DOM3EV] is dispatched on any node in a
Document
presented in a browsing context, the value of the
view
attribute of the event MUST be the
Window
object where the user originated the
event.
Window
Interface, Basic
AttributesThe Window
interface is fully specified in IDL in the IDL Definitions Appendix. To better organize this
specification, it is described in prose in mulitple IDL
fragments.
The Window
interface
inherits from the AbstractView
interface
[DOM2Views].
In implementations that support Document Object Model CSS
from DOM Level 2 Views [DOM2Views], every Window
object
MUST also implement the
ViewCSS
interface.
interface Window : views::AbstractView { // ... // self-references readonly attribute Window window; readonly attribute Window self; // ... };
The value of the document
property inherited
by Window
objects from the
AbstractView
interface MUST be the
Document
for which the Window
is a
view. As a result, in addition to the
DocumentView
interface, it implements the
Document
and DocumentWindow
interfaces.
Window
objects
MUST have the following
attributes:
window
attributewindow
attribute
MUST be the same
Window
object that has the attribute: the
attribute is a self-reference.self
attributeself
attribute
MUST be the same
Window
object that has the attribute: the
attribute is a self-reference. Consequently, the value
of the self
attribute
MUST be the same
object as the window
attribute.
The Window
object also
has a special role as the global scope for scripts in the
document in languages such as ECMAScript [ECMAScript]. Such
use is specified by individual language bindings. For
ECMAScript it is specified in the ECMAScript Language Binding Appendix.
DocumentWindow
Interface, Basic AttributesTo better organize this specification, the
DocumentWindow
interface is presented in
mulitple IDL fragments. The full normative IDL interface is
presented in the IDL Definitions Appendix.
This fragment defines only the most basic methods and
attributes of the Window
interface.
interface DocumentWindow : views::DocumentView { // ... };
The value of the defaultView
attribute
inherited by objects that implement the
DocumentWindow
interface inherit from the
AbstractView
interface MUST be the default
view for the browsing context presenting the
document, if any. In addition to the
AbstractView
interface, the default view
MUST implement the
Window
interface. If a document is not being
presented in a browsing context but nontheless
implements the DocumentWindow interface, the value of the
defaultView
attribute MUST be
null
.
Window
Interface, Location Attributesinterface Window : views::AbstractView { // ... // assigning this has special behavior in ECMAScript, but it is otherwise // read only. specifically, in ES a string URI can be assigned to location, // having the same effect as location.assign(URI) readonly attribute Location location; // ... };
Window
objects
MUST have the following
attributes:
location
attribute
MUST be the
Location
object that represents the
window's current location.
DocumentWindow
Interface, Location
Attributesinterface DocumentWindow : views::DocumentView { // ... // same special JS assignment as window.location readonly attribute Location location; // ... };
DocumentWindow
objects MUST implement the
following attributes:
location
attribute
MUST be a
Location
object that represents the
DocumentWindow
's current location. The
value MUST be the same as
the Location for all views of the document.
Location
Interfaceinterface Location { attribute dom::DOMString href; // pieces of the URI, per the generic URI syntax attribute dom::DOMString hash; attribute dom::DOMString host; attribute dom::DOMString hostname; attribute dom::DOMString pathname; attribute dom::DOMString port; attribute dom::DOMString protocol; attribute dom::DOMString search; void assign(in dom::DOMString url); void replace(in dom::DOMString url); void reload(); dom::DOMString toString(); };
Location
objects MUST implement the
following attributes:
href
attribute MUST
be the absolute URI reference [RFC2396]
href
attribute is set, the Location's
window MUST
navigate to the newly set value.
hash
attribute the value of this attribute
MUST be the string
concatenation of the hash mark(#) and the fragment
identifier. Otherwise, the value of the
hash
attribute MUST be the empty
string. When this atribute is set to a new value
new-hash, user agents MUST perform
the following steps:
port
attribute is not
null
then the host
attribute's
value is the concatenation of the hostname
attribute, a colon (:
) and the
port
attribute. If the port
attribute is null
then the host
attribute's value is identical to the
hostname
attribute.Location
objects MUST implement the
following methods:
An element that refers to another document which is then embedded is called an embedding element. A document embedded in such an element is called a child document. Seen from a child document, the embedding element is part of a parent document. When a document has no embedding element that points to it the document is a root document. A document can be both a parent document and child document at the same time.
The value of the frameElement
attribute of a
Window
object MUST be the embedding element, or
null
if there is no such element. The value of the
parent
attribute of a Window
object
MUST be the parent document's
Window
object or the document's
Window
object if there is no parent document. The
value of the top
attribute of a
Window
object MUST be the root document's
Window
object.
The name
attribute of a Window
object MUST be the name assigned by
the embedding
element, the empty string if there is no such element or a
value set by the script author. How this name is extracted from
the embedding element is language specific.
For example, if you have <object
data="file" id="test"/>
in an XHTML
document the name
DOM attribute within
file will be "test".
The value of the contentDocument
attribute of
an object that implements the EmbeddingElement
interface MUST be the child document's
Document
object or null
if there is
no such object.
contentWindow
attribute of an
object that implements the EmbeddingElement
interface MUST be the child document's
Window
object or null
if there is no
such object.
Window
Interface, Embedding Attributesinterface Window { // name attribute of referencing frame/iframe/object, or name passed to // window.open attribute dom::DOMString name; // global object of containing document readonly attribute Window parent; // global object of outermost containing document readonly attribute Window top; // referencing <html:frame>, <html:iframe>, <html:object>, <svg:foreignObject>, // <svg:animation> or other embedding point, or null if none readonly attribute dom::Element frameElement; };
Window
object that contains this object.EmbeddingElement
Interface// must be on an object that also implements dom::Element interface EmbeddingElement { readonly attribute dom::Document contentDocument; readonly attribute Window contentWindow; };
Window
Interface, Timer Attributesinterface Window { // should timers allow more than long, maybe a floating point type? // don't think anyone's timers have more precision // one-shot timer long setTimeout(in TimerListener listener, in long milliseconds); void clearTimeout(in long timerID); // repeating timer long setInterval(in TimerListener listener, in long milliseconds); void clearInterval(in long timerID); };
// behavior is always special in ECMAScript, this is defined only for the benefit // of other languages interface TimerListener { // what to put here? };
My current plan for the "security considerations" section is that it will contain the following:
I would rather not have normative requirements on when UAs must or must not throw exceptions or return null or whatever, since these would merely represent our best current understanding of how to implement the security policy.
It may be that some of this belongs in the main body of the spec instead of in Security Considerations, let's figure that out when the security part is actually written.
The WebAPI WG would like to thanks the following people for contributing to this specification:
Björn Höhrmann, Jim Ley, Cameron McCormack and Boris Zbarsky.
Special thanks to Anne van Kesteren for writing the Embedding section and many other additions and improvenets.
Special thanks to Ian Hickson for making the first attempt to standardize the Window object in Web Apps 1.0, drafts of which heavily influenced this document. In particular, he coined the term "browsing context".