HTMLBodyElement

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

Revision Content

{{ DomRef() }}

HTML body element interface

DOM body elements expose the HTMLBodyElement (or {{ HTMLVersionInline("4") }} HTMLBodyElement) interface, which provides special properties (beyond the regular {{ domxref("element") }} object interface they also have available to them by inheritance) for manipulating body elements.

Properties

Name Type Description
aLink {{obsolete_inline}} {{ domxref("DOMString") }} Color of active hyperlinks.
background {{obsolete_inline}} {{ domxref("DOMString") }}

URI for a background image resource.

Note: Starting in Gecko 7.0 {{ geckoRelease("7.0") }}, this value is no longer resolved as a URI; instead, it's treated as a simple string.
bgColor {{obsolete_inline}} {{ domxref("DOMString") }} Background color for the document.
link {{obsolete_inline}} {{ domxref("DOMString") }} Color of unvisited links.
onafterprint {{ HTMLVersionInline(5) }} {{domxref("EventHandler")}} Reflects the {{ htmlattrxref("onafterprint", "body") }} HTML attribute value for a function to call after the user has printed the document.
onbeforeprint {{ HTMLVersionInline(5) }} {{domxref("EventHandler")}} Reflects the {{ htmlattrxref("onbeforeprint", "body") }} HTML attribute value for a function to call when the user has requested printing the document.
onbeforeunload {{ HTMLVersionInline(5) }} {{domxref("EventHandler")}} Reflects the {{ htmlattrxref("onbeforeunload", "body") }} HTML attribute value for a function to call when the document is about to be unloaded.
onblur {{ HTMLVersionInline(5) }} {{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 {{ HTMLVersionInline(5) }} {{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 {{ HTMLVersionInline(5) }} {{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 {{ HTMLVersionInline(5) }} {{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 {{ HTMLVersionInline(5) }} {{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 {{ HTMLVersionInline(5) }} {{domxref("EventHandler")}} Reflects the {{ htmlattrxref("onmessage", "body") }} HTML attribute value for a function to call when the document receives a message.
onoffline {{ HTMLVersionInline(5) }} {{domxref("EventHandler")}} Reflects the {{ htmlattrxref("onoffline", "body") }} HTML attribute value for a function to call when network communication fails.
ononline {{ HTMLVersionInline(5) }} {{domxref("EventHandler")}} Reflects the {{ htmlattrxref("ononline", "body") }} HTML attribute value for a function to call when network communication is restored.
onpopstate {{ HTMLVersionInline(5) }} {{domxref("EventHandler")}} Reflects the {{ htmlattrxref("onpopstate", "body") }} HTML attribute value for a function to call when the user has navigated session history.
onresize {{ HTMLVersionInline(5) }} {{domxref("EventHandler")}} Reflects the {{ htmlattrxref("onresize", "body") }} HTML attribute value for a function to call when the document has been resized.
onstorage {{ HTMLVersionInline(5) }} {{domxref("EventHandler")}} Reflects the {{ htmlattrxref("onpopstate", "body") }} HTML attribute value for a function to call when the storage area has changed.
onunload {{ HTMLVersionInline(5) }} {{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.

See also

  • {{ HTMLElement("body") }} HTML element

Revision Source

<p>{{ DomRef() }}</p>
<h2 id="HTML_body_element_interface">HTML body element interface</h2>
<p>DOM body elements expose the <a class="external" href="http://www.w3.org/TR/html5/sections.html#the-body-element" rel="external nofollow" target="_blank" title="http://www.w3.org/TR/html5/sections.html#the-body-element">HTMLBodyElement</a> (or {{ HTMLVersionInline("4") }} <a class="external" href="http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-48250443" rel="external nofollow" target="_blank" title="http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-48250443"><code>HTMLBodyElement</code></a>) interface, which provides special properties (beyond the regular {{ domxref("element") }} object interface they also have available to them by inheritance) for manipulating body elements.</p>
<h2 id="Properties">Properties</h2>
<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> {{obsolete_inline}}</td>
      <td>{{ domxref("DOMString") }}</td>
      <td>
        <p>URI for a background image resource.</p>
        <div class="note">
          <strong>Note:</strong> Starting in Gecko 7.0 {{ geckoRelease("7.0") }}, this value is no longer resolved as a URI; instead, it's treated as a simple string.</div>
      </td>
    </tr>
    <tr>
      <td><code>bgColor</code> {{obsolete_inline}}</td>
      <td>{{ domxref("DOMString") }}</td>
      <td>Background color for the document.</td>
    </tr>
    <tr>
      <td><code>link</code> {{obsolete_inline}}</td>
      <td>{{ domxref("DOMString") }}</td>
      <td>Color of unvisited links.</td>
    </tr>
    <tr>
      <td><code>onafterprint</code> {{ HTMLVersionInline(5) }}</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> {{ HTMLVersionInline(5) }}</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> {{ HTMLVersionInline(5) }}</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> {{ HTMLVersionInline(5) }}</td>
      <td>{{domxref("EventHandler")}}</td>
      <td>
        <p>Exposes the {{ domxref("window.onblur") }} event handler to call when the window loses focus.</p>
        <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> {{ HTMLVersionInline(5) }}</td>
      <td>{{domxref("EventHandler")}}</td>
      <td>
        <p>Exposes the {{ domxref("window.onerror") }} event handler to call when the document fails to load properly.</p>
        <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> {{ HTMLVersionInline(5) }}</td>
      <td>{{domxref("EventHandler")}}</td>
      <td>
        <p>Exposes the {{ domxref("window.onfocus") }} event handler to call when the window gains focus.</p>
        <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> {{ HTMLVersionInline(5) }}</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> {{ HTMLVersionInline(5) }}</td>
      <td>{{domxref("EventHandler")}}</td>
      <td>
        <p>Exposes the {{ domxref("window.onload") }} event handler to call when the window gains focus.</p>
        <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> {{ HTMLVersionInline(5) }}</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> {{ HTMLVersionInline(5) }}</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> {{ HTMLVersionInline(5) }}</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> {{ HTMLVersionInline(5) }}</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> {{ HTMLVersionInline(5) }}</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> {{ HTMLVersionInline(5) }}</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> {{ HTMLVersionInline(5) }}</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> {{obsolete_inline}}</td>
      <td>{{ domxref("DOMString") }}</td>
      <td>Foreground color of text.</td>
    </tr>
    <tr>
      <td><code>vLink</code> {{obsolete_inline}}</td>
      <td>{{ domxref("DOMString") }}</td>
      <td>Color of visited links.</td>
    </tr>
  </tbody>
</table>
<h2 id="See_also">See also</h2>
<ul>
  <li>{{ HTMLElement("body") }} HTML&nbsp;element</li>
</ul>
Revert to this revision