--- title: HTMLBodyElement slug: Web/API/HTMLBodyElement translation_of: Web/API/HTMLBodyElement ---
{{APIRef("HTML DOM")}}
HTMLBodyElement 接口提供了特殊的属性(除了它们继承的常规的{{ domxref("HTMLElement") }}接口)以外,还可以处理 body 元素。
 

{{InheritanceDiagram(600, 120)}}

属性

从其父项{{domxref("HTMLElement")}} 和{{domxref("WindowEventHandlers")}}中继承属性。

{{domxref("HTMLBodyElement.aLink")}} {{obsolete_inline}}
Is a {{ domxref("DOMString") }} that represents the color of active hyperlinks.
{{domxref("HTMLBodyElement.background")}} {{obsolete_inline}}
Is a {{ domxref("DOMString") }} that represents the 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.
{{domxref("HTMLBodyElement.bgColor")}} {{obsolete_inline}}
Is a {{ domxref("DOMString") }} that represents the background color for the document.
{{domxref("HTMLBodyElement.link")}} {{obsolete_inline}}
Is a {{ domxref("DOMString") }} that represents the color of unvisited links.
{{domxref("HTMLBodyElement.text")}} {{obsolete_inline}}
Is a {{ domxref("DOMString") }} that represents the foreground color of text.
{{domxref("HTMLBodyElement.vLink")}} {{obsolete_inline}}
Is a {{ domxref("DOMString") }} that represents the color of visited links.

方法

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

事件处理

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

{{domxref("WindowEventHandlers.onafterprint")}}
Is an {{event("Event_handlers", "event handler")}} representing the code to be called when the {{event("afterprint")}} event is raised.
{{domxref("WindowEventHandlers.onbeforeprint")}}
Is an {{event("Event_handlers", "event handler")}} representing the code to be called when the {{event("beforeprint")}} event is raised.
{{domxref("WindowEventHandlers.onbeforeunload")}}
Is an {{event("Event_handlers", "event handler")}} representing the code to be called when the {{event("beforeunload")}} event is raised.
{{domxref("WindowEventHandlers.onhashchange")}}
Is an {{event("Event_handlers", "event handler")}} representing the code to be called when the {{event("hashchange")}} event is raised.
{{domxref("WindowEventHandlers.onlanguagechange")}} {{experimental_inline}}
Is an {{event("Event_handlers", "event handler")}} representing the code to be called when the {{event("languagechange")}} event is raised.
{{domxref("WindowEventHandlers.onmessage")}}
Is an {{event("Event_handlers", "event handler")}} called whenever an object receives a {{event("message")}} event.  
{{domxref("WindowEventHandlers.onmessageerror")}}
Is an {{event("Event_handlers", "event handler")}} called whenever an object receives a {{event("messageerror")}} event.
{{domxref("WindowEventHandlers.onoffline")}}
Is an {{event("Event_handlers", "event handler")}} representing the code to be called when the {{event("offline")}} event is raised.
{{domxref("WindowEventHandlers.ononline")}}
Is an {{event("Event_handlers", "event handler")}} representing the code to be called when the {{event("online")}} event is raised.
{{domxref("WindowEventHandlers.onpagehide")}}
Is an {{event("Event_handlers", "event handler")}} representing the code to be called when the {{event("pagehide")}} event is raised.
{{domxref("WindowEventHandlers.onpageshow")}}
Is an {{event("Event_handlers", "event handler")}} representing the code to be called when the {{event("pageshow")}} event is raised.
{{domxref("WindowEventHandlers.onpopstate")}}
Is an {{event("Event_handlers", "event handler")}} representing the code to be called when the {{event("popstate")}} event is raised.
{{domxref("WindowEventHandlers.onrejectionhandled")}}
An {{event("Event_handlers", "event handler")}} representing the code executed when the {{event("rejectionhandled")}} event is raised, indicating that a {{jsxref("Promise")}} was rejected and the rejection has been handled.
{{domxref("WindowEventHandlers.onresize")}}
Is an {{event("Event_handlers", "event handler")}} representing the code to be called when the {{event("resize")}} event is raised.
{{domxref("WindowEventHandlers.onstorage")}}
Is an {{event("Event_handlers", "event handler")}} representing the code to be called when the {{event("storage")}} event is raised.
{{domxref("WindowEventHandlers.onunhandledrejection")}}
An {{event("Event_handlers", "event handler")}} representing the code executed when the {{event("unhandledrejection")}} event is raised, indicating that a {{jsxref("Promise")}} was rejected but the rejection was not handled.
{{domxref("WindowEventHandlers.onunload")}}
Is an {{event("Event_handlers", "event handler")}} representing the code to be called when the {{event("unload")}} event is raised.

规范

Specification Status Comment
{{SpecName('HTML WHATWG', "sections.html#the-body-element", "HTMLBodyElement")}} {{Spec2('HTML WHATWG')}} Technically, the event-related properties onafterprint, onbeforeprint, onbeforeunload, onblur, onerror, onfocus, onhashchange, onlanguagechange, onload, onmessage, onoffline, ononline, onpopstate, onresize, onstorage, and onunload, have been moved to {{domxref("WindowEventHandlers")}}. HTMLBodyElement implements this interface.
{{SpecName('HTML5.1', "sections.html#the-body-element", "HTMLBodyElement")}} {{Spec2('HTML5.1')}}  
{{SpecName('HTML5 W3C', "sections.html#the-body-element", "HTMLBodyElement")}} {{Spec2('HTML5 W3C')}} 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.
{{SpecName('DOM2 HTML', 'html.html#ID-62018039', 'HTMLBodyElement')}} {{Spec2('DOM2 HTML')}} No change from {{SpecName("DOM1")}}.
{{SpecName('DOM1', 'level-one-html.html#ID-62018039', 'HTMLBodyElement')}} {{Spec2('DOM1')}} Initial definition.

浏览器兼容性

{{Compat("api.HTMLBodyElement")}}

参考阅读