HTMLBodyElement

This article is in need of a technical review.

« HTMLBodyElement

The HTMLBodyElement interface provides special properties (beyond those of the regular HTMLElement interface they also inherit) for manipulating body elements.

Properties

Inherits properties from its parent, HTMLElement and from WindowEventHandlers.

Name Type Description
aLink 
DOMString Color of active hyperlinks.
background 
DOMString Description of the location of the background image resource. Note that this is not an URI, though some older version of some browsers do expect it. [1]
bgColor 
DOMString Background color for the document.
link 
DOMString Color of unvisited links.
onafterprint EventHandler Reflects the onafterprint HTML attribute value for a function to call after the user has printed the document.
onbeforeprint EventHandler Reflects the onbeforeprint HTML attribute value for a function to call when the user has requested printing the document.
onbeforeunload EventHandler Reflects the onbeforeunload HTML attribute value for a function to call when the document is about to be unloaded.
onblur EventHandler Exposes the window.onblur event handler to call when the window loses focus.
Note: This handler is triggered when the event reaches the window, not the body element. Use addEventListener() to attach an event listener to the body element.
onerror EventHandler Exposes the window.onerror event handler to call when the document fails to load properly.
Note: This handler is triggered when the event reaches the window, not the body element. Use addEventListener() to attach an event listener to the body element.
onfocus EventHandler Exposes the window.onfocus event handler to call when the window gains focus.
Note: This handler is triggered when the event reaches the window, not the body element. Use addEventListener() to attach an event listener to the body element.
onhashchange EventHandler Reflects the onhashchange HTML attribute value for a function to call when the fragment identifier in the address of the document changes.
onload EventHandler Exposes the window.onload event handler to call when the window gains focus.
Note: This handler is triggered when the event reaches the window, not the body element. Use addEventListener() to attach an event listener to the body element.
onmessage EventHandler Reflects the onmessage HTML attribute value for a function to call when the document receives a message.
onoffline EventHandler Reflects the onoffline HTML attribute value for a function to call when network communication fails.
ononline EventHandler Reflects the ononline HTML attribute value for a function to call when network communication is restored.
onpopstate EventHandler Reflects the onpopstate HTML attribute value for a function to call when the user has navigated session history.
onresize EventHandler Reflects the onresize HTML attribute value for a function to call when the document has been resized.
onstorage EventHandler Reflects the onpopstate HTML attribute value for a function to call when the storage area has changed.
onunload EventHandler Reflects the onunload HTML attribute value for a function to call when when the document is going away.
text  DOMString Foreground color of text.
vLink  DOMString Color of visited links.

Methods

No specific method; inherits methods from its parent, HTMLElement and from WindowEventHandlers.

Specifications

Specification Status Comment
WHATWG HTML Living Standard Living Standard Technically, the event-related properties,onafterprint, onbeforeprint, onbeforeunload, onblur, onerror, onfocus, onhashchange, onload, onmessage, onoffline, ononline, onpopstate, onresize, onstorage, and onunload, have been moving to the WindowEventHandlers interface, and HTMLBodyElement implements this interface.
HTML5 Candidate Recommendation The following properties are now obsolete: aLink, bgColor, background, link, text, and vLink.
The following properties have been added: onafterprint, onbeforeprint, onbeforeunload, onblur, onerror, onfocus, onhashchange, onload, onmessage, onoffline, ononline, onpopstate, onresize, onstorage, and onunload.
Document Object Model (DOM) Level 2 HTML Specification Recommendation No change from Document Object Model (DOM) Level 1 Specification.
Document Object Model (DOM) Level 1 Specification Recommendation Initial definition.

Browser compatibility

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support 1.0 1.0 (1.7 or earlier) [1] 4.0 (Yes) [1] (Yes)
onXYZ event handlers (Yes) (Yes) ? ? ?
Feature Android Firefox Mobile (Gecko) IE Phone Opera Mobile Safari Mobile
Basic support (Yes) 1.0 (1.0) (Yes) (Yes) (Yes)
onXYZ event handlers (Yes) (Yes) ? ? ?

[1] Firefox prior to Firefox 7.0 and some older versions of Opera did returned an URI for the HTMLBodyElement.background attribute.

See also

  • HTML element implementing this interface: <body>

Document Tags and Contributors

Contributors to this page: Sheppy, mua, imsaikat, jswisher, trevorh, kscarfone, teoli, Ms2ger
Last updated by: teoli,