HTMLBodyElement

  • Revision slug: DOM/HTMLBodyElement
  • Revision title: HTMLBodyElement
  • Revision id: 389625
  • Created:
  • Creator: teoli
  • Is current revision? No
  • Comment

Revision Content

{{DomRef}}

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

Properties

Inherits attributes from its parent, {{domxref("HTMLElement")}} and from {{domxref("WindowEventHandlers")}}.

Name Type Description
aLink {{obsolete_inline}} {{ domxref("DOMString") }} Color of active hyperlinks.
background {{obsolete_inline}} {{ domxref("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 {{obsolete_inline}} {{ domxref("DOMString") }} Background color for the document.
link {{obsolete_inline}} {{ domxref("DOMString") }} Color of unvisited links.
onafterprint {{domxref("EventHandler")}} Reflects the {{ htmlattrxref("onafterprint", "body") }} HTML attribute value for a function to call after the user has printed the document.
onbeforeprint {{domxref("EventHandler")}} Reflects the {{ htmlattrxref("onbeforeprint", "body") }} HTML attribute value for a function to call when the user has requested printing the document.
onbeforeunload {{domxref("EventHandler")}} Reflects the {{ htmlattrxref("onbeforeunload", "body") }} HTML attribute value for a function to call when the document is about to be unloaded.
onblur {{domxref("EventHandler")}} Exposes the {{ domxref("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 {{ domxref("element.addEventListener","addEventListener()") }} to attach an event listener to the body element.
onerror {{domxref("EventHandler")}} Exposes the {{ domxref("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 {{ domxref("element.addEventListener","addEventListener()") }} to attach an event listener to the body element.
onfocus {{domxref("EventHandler")}} Exposes the {{ domxref("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 {{ domxref("element.addEventListener","addEventListener()") }} to attach an event listener to the body element.
onhashchange {{domxref("EventHandler")}} Reflects the {{ htmlattrxref("onhashchange", "body") }} HTML attribute value for a function to call when the fragment identifier in the address of the document changes.
onload {{domxref("EventHandler")}} Exposes the {{ domxref("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 {{ domxref("element.addEventListener","addEventListener()") }} to attach an event listener to the body element.
onmessage {{domxref("EventHandler")}} Reflects the {{ htmlattrxref("onmessage", "body") }} HTML attribute value for a function to call when the document receives a message.
onoffline {{domxref("EventHandler")}} Reflects the {{ htmlattrxref("onoffline", "body") }} HTML attribute value for a function to call when network communication fails.
ononline {{domxref("EventHandler")}} Reflects the {{ htmlattrxref("ononline", "body") }} HTML attribute value for a function to call when network communication is restored.
onpopstate {{domxref("EventHandler")}} Reflects the {{ htmlattrxref("onpopstate", "body") }} HTML attribute value for a function to call when the user has navigated session history.
onresize {{domxref("EventHandler")}} Reflects the {{ htmlattrxref("onresize", "body") }} HTML attribute value for a function to call when the document has been resized.
onstorage {{domxref("EventHandler")}} Reflects the {{ htmlattrxref("onpopstate", "body") }} HTML attribute value for a function to call when the storage area has changed.
onunload {{domxref("EventHandler")}} Reflects the {{ htmlattrxref("onunload", "body") }} HTML attribute value for a function to call when when the document is going away.
text {{obsolete_inline}} {{ domxref("DOMString") }} Foreground color of text.
vLink {{obsolete_inline}} {{ domxref("DOMString") }} Color of visited links.

Methods

No specific method; inherits attributes from its parent, {{domxref("HTMLElement")}} and from {{domxref("WindowEventHandlers")}}.

Specifications

Specification Status Comment
{{SpecName('HTML WHATWG', "sections.html#the-body-element", "HTMLBodyElement")}} {{Spec2('HTML WHATWG')}} Technically the event-related attributes,onafterprint, onbeforeprint, onbeforeunload, onblur, onerror, onfocus, onhashchange, onload, onmessage, onoffline, ononline, onpopstate, onresize, onstorage, and onunload, have been moving to the {{domxref("WindowEventHandlers")}} interface, and HTMLBodyElement implements this interface.
{{SpecName('HTML5 W3C', "sections.html#the-body-element", "HTMLBodyElement")}} {{Spec2('HTML5 W3C')}} The following attributes are now obsolete: aLink, bgColor, background, link, text, and vLink.
The following attributes have been added: onafterprint, onbeforeprint, onbeforeunload, onblur, onerror, onfocus, onhashchange, onload, onmessage, onoffline, ononline, onpopstate, onresize, onstorage, and onunload.
{{SpecName('DOM2 HTML', 'html.html#ID-ID-62018039', 'HTMLBodyElement')}} {{Spec2('DOM2 HTML')}} No change from {{SpecName("DOM1")}}.
{{SpecName('DOM1', 'level-one-html.html#ID-62018039', 'HTMLBodyElement')}} {{Spec2('DOM1')}} Initial definition.

Browser compatibility

{{CompatibilityTable}}

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support 1.0 {{CompatGeckoDesktop(1.0)}} [1] 4.0 {{CompatVersionUnknown}} [1] {{CompatVersionUnknown}}
onXYZ event handlers {{CompatVersionUnknown}} {{CompatVersionUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}
Feature Android Firefox Mobile (Gecko) IE Phone Opera Mobile Safari Mobile
Basic support {{CompatVersionUnknown}} {{CompatGeckoMobile(1.0)}} {{CompatVersionUnknown}} {{CompatVersionUnknown}} {{CompatVersionUnknown}}
onXYZ event handlers {{CompatVersionUnknown}} {{CompatVersionUnknown}} {{CompatUnknown}} {{CompatUnknown}} {{CompatUnknown}}

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

See also

  • HTML element implementing this interface: {{ HTMLElement("body") }}

Revision Source

<p>{{DomRef}}</p>
<p>The <strong><code>HTMLBodyElement</code></strong> interface provides special properties (beyond those of the regular {{ domxref("HTMLElement") }} interface they also inherit) for manipulating body elements.</p>
<h2 id="Properties">Properties</h2>
<p><em>Inherits attributes from its parent, {{domxref("HTMLElement")}} and from {{domxref("</em>WindowEventHandlers<em>")}}.</em></p>
<table class="standard-table">
  <thead>
    <tr>
      <th scope="col">Name</th>
      <th scope="col">Type</th>
      <th scope="col">Description</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td><code>aLink</code>&nbsp;{{obsolete_inline}}</td>
      <td>{{ domxref("DOMString") }}</td>
      <td>Color of active hyperlinks.</td>
    </tr>
    <tr>
      <td><code>background</code>&nbsp;{{obsolete_inline}}</td>
      <td>{{ domxref("DOMString") }}</td>
      <td>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]</td>
    </tr>
    <tr>
      <td><code>bgColor</code>&nbsp;{{obsolete_inline}}</td>
      <td>{{ domxref("DOMString") }}</td>
      <td>Background color for the document.</td>
    </tr>
    <tr>
      <td><code>link</code>&nbsp;{{obsolete_inline}}</td>
      <td>{{ domxref("DOMString") }}</td>
      <td>Color of unvisited links.</td>
    </tr>
    <tr>
      <td><code>onafterprint</code></td>
      <td>{{domxref("EventHandler")}}</td>
      <td>Reflects the {{ htmlattrxref("onafterprint", "body") }} HTML&nbsp;attribute value for a function to call after the user has printed the document.</td>
    </tr>
    <tr>
      <td><code>onbeforeprint</code></td>
      <td>{{domxref("EventHandler")}}</td>
      <td>Reflects the {{ htmlattrxref("onbeforeprint", "body") }} HTML&nbsp;attribute value for a function to call when the user has requested printing the document.</td>
    </tr>
    <tr>
      <td><code>onbeforeunload</code></td>
      <td>{{domxref("EventHandler")}}</td>
      <td>Reflects the {{ htmlattrxref("onbeforeunload", "body") }} HTML&nbsp;attribute value for a function to call when the document is about to be unloaded.</td>
    </tr>
    <tr>
      <td><code>onblur</code></td>
      <td>{{domxref("EventHandler")}}</td>
      <td>Exposes the {{ domxref("window.onblur") }} event handler to call when the window loses focus.
        <div class="note">
          <strong>Note:</strong> This handler is triggered when the event reaches the window, not the body element. Use {{ domxref("element.addEventListener","addEventListener()") }} to attach an event listener to the body element.</div>
      </td>
    </tr>
    <tr>
      <td><code>onerror</code></td>
      <td>{{domxref("EventHandler")}}</td>
      <td>Exposes the {{ domxref("window.onerror") }} event handler to call when the document fails to load properly.
        <div class="note">
          <strong>Note:</strong> This handler is triggered when the event reaches the window, not the body element. Use {{ domxref("element.addEventListener","addEventListener()") }} to attach an event listener to the body element.</div>
      </td>
    </tr>
    <tr>
      <td><code>onfocus</code></td>
      <td>{{domxref("EventHandler")}}</td>
      <td>Exposes the {{ domxref("window.onfocus") }} event handler to call when the window gains focus.
        <div class="note">
          <strong>Note:</strong> This handler is triggered when the event reaches the window, not the body element. Use {{ domxref("element.addEventListener","addEventListener()") }} to attach an event listener to the body element.</div>
      </td>
    </tr>
    <tr>
      <td><code>onhashchange</code></td>
      <td>{{domxref("EventHandler")}}</td>
      <td>Reflects the {{ htmlattrxref("onhashchange", "body") }} HTML&nbsp;attribute value for a function to call when the fragment identifier in the address of the document changes.</td>
    </tr>
    <tr>
      <td><code>onload</code></td>
      <td>{{domxref("EventHandler")}}</td>
      <td>Exposes the {{ domxref("window.onload") }} event handler to call when the window gains focus.
        <div class="note">
          <strong>Note:</strong> This handler is triggered when the event reaches the window, not the body element. Use {{ domxref("element.addEventListener","addEventListener()") }} to attach an event listener to the body element.</div>
      </td>
    </tr>
    <tr>
      <td><code>onmessage</code></td>
      <td>{{domxref("EventHandler")}}</td>
      <td>Reflects the {{ htmlattrxref("onmessage", "body") }} HTML&nbsp;attribute value for a function to call when the document receives a message.</td>
    </tr>
    <tr>
      <td><code>onoffline</code></td>
      <td>{{domxref("EventHandler")}}</td>
      <td>Reflects the {{ htmlattrxref("onoffline", "body") }} HTML&nbsp;attribute value for a function to call when network communication fails.</td>
    </tr>
    <tr>
      <td><code>ononline</code></td>
      <td>{{domxref("EventHandler")}}</td>
      <td>Reflects the {{ htmlattrxref("ononline", "body") }} HTML&nbsp;attribute value for a function to call when network communication is restored.</td>
    </tr>
    <tr>
      <td><code>onpopstate</code></td>
      <td>{{domxref("EventHandler")}}</td>
      <td>Reflects the {{ htmlattrxref("onpopstate", "body") }} HTML&nbsp;attribute value for a function to call when the user has navigated session history.</td>
    </tr>
    <tr>
      <td><code>onresize</code></td>
      <td>{{domxref("EventHandler")}}</td>
      <td>Reflects the {{ htmlattrxref("onresize", "body") }} HTML&nbsp;attribute value for a function to call when the document has been resized.</td>
    </tr>
    <tr>
      <td><code>onstorage</code></td>
      <td>{{domxref("EventHandler")}}</td>
      <td>Reflects the {{ htmlattrxref("onpopstate", "body") }} HTML&nbsp;attribute value for a function to call when the storage area has changed.</td>
    </tr>
    <tr>
      <td><code>onunload</code></td>
      <td>{{domxref("EventHandler")}}</td>
      <td>Reflects the {{ htmlattrxref("onunload", "body") }} HTML&nbsp;attribute value for a function to call when when the document is going away.</td>
    </tr>
    <tr>
      <td><code>text</code>&nbsp;{{obsolete_inline}}</td>
      <td>{{ domxref("DOMString") }}</td>
      <td>Foreground color of text.</td>
    </tr>
    <tr>
      <td><code>vLink</code>&nbsp;{{obsolete_inline}}</td>
      <td>{{ domxref("DOMString") }}</td>
      <td>Color of visited links.</td>
    </tr>
  </tbody>
</table>
<h2>Methods</h2>
<p><em>No specific method; inherits attributes from its parent, {{domxref("HTMLElement")}} and from {{domxref("</em>WindowEventHandlers<em>")}}.</em></p>
<h2 id="Specifications">Specifications</h2>
<table class="standard-table">
  <tbody>
    <tr>
      <th scope="col">Specification</th>
      <th scope="col">Status</th>
      <th scope="col">Comment</th>
    </tr>
    <tr>
      <td>{{SpecName('HTML WHATWG', "sections.html#the-body-element", "HTMLBodyElement")}}</td>
      <td>{{Spec2('HTML WHATWG')}}</td>
      <td>Technically the event-related attributes,<code>onafterprint</code>, <code>onbeforeprint</code>, <code>onbeforeunload</code>, <code>onblur</code>, <code>onerror</code>, <code>onfocus</code>, <code>onhashchange</code>, <code>onload</code>, <code>onmessage</code>, <code>onoffline</code>, <code>ononline</code>, <code>onpopstate</code>, <code>onresize</code>, <code>onstorage</code>, and <code>onunload</code>, have been moving to the {{domxref("WindowEventHandlers")}} interface, and <code>HTMLBodyElement</code> implements this interface.</td>
    </tr>
    <tr>
      <td>{{SpecName('HTML5 W3C', "sections.html#the-body-element", "HTMLBodyElement")}}</td>
      <td>{{Spec2('HTML5 W3C')}}</td>
      <td>The following attributes are now obsolete: <code>aLink</code>, <code>bgColor</code>, <code>background</code>, <code>link</code>, <code>text</code>, and <code>vLink</code>.<br />
        The following attributes have been added: <code>onafterprint</code>, <code>onbeforeprint</code>, <code>onbeforeunload</code>, <code>onblur</code>, <code>onerror</code>, <code>onfocus</code>, <code>onhashchange</code>, <code>onload</code>, <code>onmessage</code>, <code>onoffline</code>, <code>ononline</code>, <code>onpopstate</code>, <code>onresize</code>, <code>onstorage</code>, and <code>onunload</code>.</td>
    </tr>
    <tr>
      <td>{{SpecName('DOM2 HTML', 'html.html#ID-ID-62018039', 'HTMLBodyElement')}}</td>
      <td>{{Spec2('DOM2 HTML')}}</td>
      <td>No change from {{SpecName("DOM1")}}.</td>
    </tr>
    <tr>
      <td>{{SpecName('DOM1', 'level-one-html.html#ID-62018039', 'HTMLBodyElement')}}</td>
      <td>{{Spec2('DOM1')}}</td>
      <td>Initial definition.</td>
    </tr>
  </tbody>
</table>
<h2 id="Browser_compatibility">Browser compatibility</h2>
<p>{{CompatibilityTable}}</p>
<div id="compat-desktop">
  <table class="compat-table">
    <tbody>
      <tr>
        <th>Feature</th>
        <th>Chrome</th>
        <th>Firefox (Gecko)</th>
        <th>Internet Explorer</th>
        <th>Opera</th>
        <th>Safari (WebKit)</th>
      </tr>
      <tr>
        <td>Basic support</td>
        <td>1.0</td>
        <td>{{CompatGeckoDesktop(1.0)}} [1]</td>
        <td>4.0</td>
        <td>{{CompatVersionUnknown}} [1]</td>
        <td>{{CompatVersionUnknown}}</td>
      </tr>
      <tr>
        <td><code>onXYZ</code> event handlers</td>
        <td>{{CompatVersionUnknown}}</td>
        <td>{{CompatVersionUnknown}}</td>
        <td>{{CompatUnknown}}</td>
        <td>{{CompatUnknown}}</td>
        <td>{{CompatUnknown}}</td>
      </tr>
    </tbody>
  </table>
</div>
<div id="compat-mobile">
  <table class="compat-table">
    <tbody>
      <tr>
        <th>Feature</th>
        <th>Android</th>
        <th>Firefox Mobile (Gecko)</th>
        <th>IE Phone</th>
        <th>Opera Mobile</th>
        <th>Safari Mobile</th>
      </tr>
      <tr>
        <td>Basic support</td>
        <td>{{CompatVersionUnknown}}</td>
        <td>{{CompatGeckoMobile(1.0)}}</td>
        <td>{{CompatVersionUnknown}}</td>
        <td>{{CompatVersionUnknown}}</td>
        <td>{{CompatVersionUnknown}}</td>
      </tr>
      <tr>
        <td><code>onXYZ</code> event handlers</td>
        <td>{{CompatVersionUnknown}}</td>
        <td>{{CompatVersionUnknown}}</td>
        <td>{{CompatUnknown}}</td>
        <td>{{CompatUnknown}}</td>
        <td>{{CompatUnknown}}</td>
      </tr>
    </tbody>
  </table>
</div>
<p>[1] Firerfox prior to Firefox 7.0 and some older version of Opera did returned an URI for the <code>HTMLBodyElement.background</code> attribute.</p>
<h2 id="See_also">See also</h2>
<ul>
  <li>HTML element implementing this interface: {{ HTMLElement("body") }}</li>
</ul>
Revert to this revision