DOM - Document (Object)

> (World Wide) Web - (W3|WWW) > The Document Object Model W3C API Interface (DOM)

1 - About

Every XML doc and HTML document (Web page) in an HTML UA is represented by a Document object.

A document in the context of a browser is generally a HTML document (Web Page).

The Document interface is the entry point to the whole DOM tree.

In a browser, it represents the whole web page.

A Document is created (the creation of the DOM):


3 - Property

3.1 - Address

The document's address is an absolute URL that is initially set when the Document is created but 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.

3.2 - Referrer

The document . referrer returns the address of the Document (an absolute URL) from which the user navigated. If it is not explicitly set, then its value is the empty string.

document . cookie 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.

With the Web API and Document cookie property

  • Set two cookies
document.cookie = "name=nico";
document.cookie = "favorite_color=blue";
  • Read the cookies
console.log("All the cookies:");
cookie_key = "name";
// because we are using a variable, we need to use constructor
regexp = new RegExp("(?:(?:^|.*;\\s*)"+cookie_key+"\\s*\\=\\s*([^;]*).*$)|^.*$");
var cookieValue = document.cookie.replace(regexp, "$1");
// Space line
console.log("The value of the cookie with the name key is ("+cookieValue+")");
  • Result (For the Google cookie, see ga.js)


3.4 - State

3.5 - Type

  • HTML,
  • XML,
  • SVG,

With the Javascript document variable

type = document.contentType;
console.log("The document type is ("+type+")");

4 - Flag

4.1 - Reload

Each Document object has a reload override flag that is originally unset. The flag is set by the and document.write() methods in certain situations.

5 - Documentation / Reference

web/dom/document.txt · Last modified: 2019/03/05 17:08 by gerardnico