3 semantics, structure, and apis of html documents — html5

Download 3 Semantics, structure, and APIs of HTML documents — HTML5

Post on 23-Oct-2015

9 views

Category:

Documents

1 download

Embed Size (px)

TRANSCRIPT

  • HTML5A vocabulary and associated APIs for HTML and XHTML

    Editor's Draft 7 November 2013 2 Common infrastructure Table of contents 4 The elements of HTML

    3 Semantics, structure, and APIs of HTML documents3.1 Documents

    3.1.1 The Document object3.1.2 Security3.1.3 Resource metadata management3.1.4 DOM tree accessors3.1.5 Loading XML documents

    3.2 Elements3.2.1 Semantics3.2.2 Elements in the DOM3.2.3 Global attributes

    3.2.3.1 The id attribute3.2.3.2 The title attribute3.2.3.3 The lang and xml:lang attributes3.2.3.4 The translate attribute3.2.3.5 The xml:base attribute (XML only)3.2.3.6 The dir attribute3.2.3.7 The class attribute3.2.3.8 The style attribute3.2.3.9 Embedding custom non-visible data with the data-* attributes

    3.2.4 Element definitions3.2.4.1 Attributes

    3.2.5 Content models3.2.5.1 Kinds of content

    3.2.5.1.1 Metadata content3.2.5.1.2 Flow content3.2.5.1.3 Sectioning content3.2.5.1.4 Heading content3.2.5.1.5 Phrasing content3.2.5.1.6 Embedded content3.2.5.1.7 Interactive content3.2.5.1.8 Palpable content3.2.5.1.9 Script-supporting elements

    3.2.5.2 Transparent content models3.2.5.3 Paragraphs

    3.2.6 Requirements relating to bidirectional-algorithm formatting characters3.2.7 WAI-ARIA

    3.2.7.1 ARIA Role Attribute3.2.7.2 State and Property Attributes3.2.7.3 Strong Native Semantics3.2.7.4 Implicit ARIA Semantics

    3.3 Interactions with XPath and XSLT3.4 Dynamic markup insertion

    3.4.1 Opening the input stream3.4.2 Closing the input stream3.4.3 document.write()3.4.4 document.writeln()

    3 Semantics, structure, and APIs of HTML documents HTML5 http://www.w3.org/html/wg/drafts/html/CR/dom.html#dom

    1 of 33 08/11/2013 11:46 a.m.

  • 3 Semantics, structure, and APIs of HTML documents

    3.1 Documents

    Every XML and HTML document in an HTML UA is represented by a Document object. [DOM]

    The document's address is an absolute URL that is initially set when the Document is created but that can change during the lifetime ofthe Document, for example when the user navigates to a fragment identifier on the page or when the pushState() method is called with anew URL.

    Warning! Interactive user agents typically expose the document's address in their user interface. This is the primary mechanismby which a user can tell if a site is attempting to impersonate another.

    When a Document is created by a script using the createDocument() or createHTMLDocument() APIs, the document's address is the same asthe document's address of the script's document, and the Document is both ready for post-load tasks and completely loaded immediately.

    The document's referrer is an absolute URL that can be set when the Document is created. If it is not explicitly set, then its value is theempty string.

    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 usedas 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.1.

    Let address be the browsing context's active document's address.2.

    Navigate the browsing context to a resource whose source is source , with replacement enabled. When the navigate algorithmcreates a Document object for this purpose, set that Document's reload override flag and set its reload override buffer to source .

    When it comes time to set the document's address in the navigation algorithm, use address as the override URL.

    3.

    The DOM specification defines a Document interface, which this specification extends significantly:

    enum DocumentReadyState { "loading", "interactive", "complete" };[OverrideBuiltins]partial /*sealed*/ interface Document { // resource metadata management [PutForwards=href, Unforgeable] readonly attribute Location? location; attribute DOMString domain; readonly attribute DOMString referrer; attribute DOMString cookie; readonly attribute DOMString lastModified; readonly attribute DocumentReadyState 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 = "text/html", optional DOMString replace = ""); WindowProxy open(DOMString url, DOMString name, DOMString features, optional boolean replace = false); 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, optional boolean showUI = false, optional DOMString value = ""); boolean queryCommandEnabled(DOMString commandId); boolean queryCommandIndeterm(DOMString commandId); boolean queryCommandState(DOMString commandId);

    IDL

    3.1.1 The Document object

    3 Semantics, structure, and APIs of HTML documents HTML5 http://www.w3.org/html/wg/drafts/html/CR/dom.html#dom

    2 of 33 08/11/2013 11:46 a.m.

  • User agents must throw a SecurityError exception whenever any properties of a Document object are accessed when the incumbent scripthas an effective script origin that is not the same as the Document's effective script origin.

    When the incumbent script's effective script origin is different than a Document object's effective script origin, the user agent must act as ifall the properties of that Document object had their [[Enumerable]] attribute set to false.

    This definition is non-normative. Implementation requirements are given below this definition.document . referrer

    Returns the address of the Document from which the user navigated to this one, unless it was blocked or there was no suchdocument, in which case it returns the empty string.The noreferrer link type can be used to block the referrer.

    The referrer attribute must return the document's referrer.

    Note: In the case of HTTP, the referrer IDL attribute will match the Referer (sic) header that was sent when fetching the currentpage.

    Note: Typically user agents are configured to not report referrers in the case where the referrer uses an encrypted protocol andthe current page does not (e.g. when navigating from an https: page to an http: page).

    This definition is non-normative. Implementation requirements are given below this definition.document . 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, theempty 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 (e.g. in an iframe with the sandbox attribute), a SecurityError exception will bethrown on getting and setting.

    The cookie attribute represents the cookies of the resource identified by the document's address.

    A Document object that falls into one of the following conditions is a cookie-averse Document object:

    A Document that has no browsing context.

    A Document whose address does not use a server-based naming authority.

    On getting, if the document is a cookie-averse Document object, then the user agent must return the empty string. Otherwise, if theDocument's origin is not a scheme/host/port tuple, the user agent must throw a SecurityError exception. Otherwise, the user agent mustfirst obtain the storage mutex and then return the cookie-string for the document's address for a "non-HTTP" API, decoded using the

    UTF-8 decoder. [COOKIES]

    On setting, if the document is a cookie-averse Document object, then the user agent must do nothing. Otherwise, if the Document's origin isnot a scheme/host/port tuple, the user agent must throw a SecurityError exception. Otherwise, the user agent must obtain the storagemutex 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 newvalue encoded as UTF-8. [COOKIES] [RFC3629]

    Note: Since the cookie attribute is accessible across frames, the path restrictions on cookies are only a tool to help managewhich cookies are sent to which parts of the site, and are not in any way a security feature.

    This definition is non-normative. Implementation requirements are given below this definition.document . 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 theuser's local time zone.

    boolean queryCommandSupported(DOMString commandId); DOMString queryCommandValue(DOMString commandId);

    // special event handler IDL attributes that only apply to Document objects [LenientThis] attribute EventHandler onreadystatechange;};Document implements GlobalEventHandlers;

    3.1.2 Security

    3.1.3 Resource metadata management

    3 Semantics, structure, and APIs of HTML documents HTML5 http://www.w3.org/html/wg/drafts/html/CR/dom.html#dom

    3 of 33 08/11/2013 11:46 a.m.

  • If the last modification date is not known, the current time is returned instead.