bodyNN 6 IE 4 DOM 1  

  

The body object reflects the body element, which is distinct from the document object. The body object refers to just the element and its nested content. There can be only one body element in an HTML page, so both the IE and W3C DOMs provide a shortcut reference to the object, document.body. Event handlers listed here appear as attributes in the <body> tag, but in truth are document-level events (best referenced in property form as document.eventName). While IE for the Mac doesn't share the sets of client and scroll properties with all element objects, those properties are defined for the body object.

 

In its effort to institute the standards-compatible mode in IE 6 for Windows (see the DOCTYPE element in Chapter 8), Microsoft has rendered useless the old trick of using the body element's clientHeight and clientWidth properties to obtain the equivalent of Netscape's window.innerHeight and window.innerWidth properties. In standards-compatibility mode (where document.compatMode == "CSS1Compat"), you must use the html element's clientHeight and clientWidth properties to find these values. Use these effective reference shortcuts:

document.body.parentNode.clientHeight
document.body.parentNode.clientWidth
 
HTML Equivalent
 
<body>
 
Object Model Reference
 
[window.]document.body
 
Object-Specific Properties
 
alinkbackgroundbgColorbgPropertiesbottomMargin
leftMarginlinknoWraprightMarginscroll
texttopMarginvLink
 
Object-Specific Methods
 
createTextRange( )
 
Object-Specific Event Handler Properties
 
HandlerIE WindowsIE MacNNW3C DOM
onafterprint5n/an/an/a
onbeforeprint5n/an/an/a
onbeforeunload4n/an/an/a
onload33.0122
onselectn/an/a6n/a
onunload33.0122
accessKeyNN n/a IE 4 DOM 1  

Read/Write  

This is single character key that either gives focus to an element (in some browsers) or activates a form control or link action. The browser and operating system determine if the user must press a modifier key (e.g., Ctrl, Alt, or Command) with the access key to activate the link. In Windows versions of IE 5 and later and Netscape 6, the Alt key is required and the key is not case-sensitive. For Macintosh versions of IE 5 and later and Netscape 6, the Ctrl modifier key is required to effect the action.

 

Although listed here as a widely shared property, that isn't strictly the case across all implementations. Netscape 6 (per the W3C DOM) recognizes this property only for the following elements: a, area, button, input, label, legend, and textarea. To this list, IE 4 adds applet, body, div, embed, isindex, marquee, object, select, span, table, and td (but removes label and legend). IE 5 adds every other renderable element, but with a caution. Except for input and other form-related elements, you must also assign a tabindex attribute or tabIndex property value to the IE 5 and later element (even if it's simply a value of zero for all) to let the accelerator key combination bring focus to the element. As of Version 7, Netscape does not alter UI behavior if a script changes the property's value.

 
Example
 
document.links[3].accessKey = "n";
 
Value

Single alphanumeric (and punctuation) keyboard character.

 
Default

Empty string.

backgroundNN 6 IE 4 DOM 1  

Read/Write  

Provides the URL of the background image for the entire document. If you set a bgColor to the element as well, the color appears if the image fails to load; otherwise, the image overlays the color.

 
Example
 
document.body.background = "images/watermark.jpg";
 
Value

Complete or relative URL to the background image file.

 
Default

None.

bgColorNN 6 IE 4 DOM 1  

Read/Write  

Provides the background color of the element. Even if the bgcolor attribute or bgColor property is set with a plain-language color name, the returned value is always a hexadecimal triplet.

 
Example
 
document.body.bgColor = "yellow";
 
Value

A hexadecimal triplet or plain-language color name. See Appendix A for acceptable plain-language color names.

 
Default

Varies with browser and operating system.

bgPropertiesNN n/a IE 4 DOM n/a  

Read/Write  

Specifies whether the background image remains in a fixed position or scrolls as a user scrolls the page. When the background image is set to remain in a fixed position, scrolled content flows past the background image very much like film credits roll past a background image on the screen.

 
Example
 
document.body.bgProperties = "fixed";
 
Value

An empty string (indicating the normal scrolling behavior) or the case-insensitive constant string fixed.

 
Default

Empty string.

bottomMarginNN n/a IE 4 DOM n/a  

Read/Write  

Indicates the amount of blank space between the very end of content and the bottom of a scrollable page. The setting has no visual effect if the length of the content or size of the window does not cause the window to scroll. The default value is for the end of content to be flush with the end of the document, but in the Macintosh version of Internet Explorer, there is about a 10-pixel margin visible even when the property is set to zero. Larger sizes are reflected properly. This property offers somewhat of a shortcut or alternative to setting the marginBottom style sheet property for the body element object.

 
Example
 
document.body.bottomMargin = 20;
 
Value

An integer value (zero or greater) of the number of pixels of clear space at the bottom of the document.

 
Default

0

clientHeight, clientWidthNN 7 IE 4 DOM n/a  

Read-only  

Broadly speaking, these provide the height and width of the element's content, but with minor variations with respect to element padding among various operating system versions of IE and compatibility modes controlled by the DOCTYPE declaration. Not available for all element types in IE for Macintosh. For Netscape 7, values are zero except when an element's content overflows the viewable area, in which case the values reveal the dimensions of the viewable area (e.g., the browser window's content region for the document.body element). See the Section 9.2 at the beginning of this chapter for details.

 
Example
 
var midHeight = document.body.clientHeight/2;
 
Value

Integer pixel value.

 
Default

0

clientLeft, clientTopNN n/a IE 4 DOM n/a  

Read-only  

Broadly speaking, these provide the left and top coordinates of the element's content within the box that includes the element's padding, but with minor variations among various operating system versions of IE. Not available for all element types in IE for Macintosh. See the Section 9.2 at the beginning of this chapter for details. More useful information for inline element positioning generally comes from the offsetLeft and offsetTop properties (including Netscape 6). For CSS-positioned elements (including changing an element's position), use style object properties, such as left and top, and (in IE only) pixelLeft and pixelTop.

 
Value

Integer pixel value.

 
Default

0

leftMarginNN n/a IE 4 DOM n/a  

Read/Write  

Provides the width in pixels of the left margin of the body element in the browser window or frame. By default, the browser inserts a small margin to keep content from abutting the left edge of the window. Setting the property to an empty string is the same as setting it to zero.

 
Example
 
document.body.leftMargin = 16;
 
Value

Integer of pixel count.

 
Default

10 (Windows); 8 (Macintosh).

isTextEditNN n/a IE 4 DOM n/a  

Read-only  

Specifies whether the element can be used to create an IE/Windows TextRange object (via the createTextRange( ) method). Only body, button, text type input, and textarea elements are permitted to have text ranges created for their content.

 
Example
 
if (document.getElementById("elementID").isTextEdit) {
		    var rng = document.getElementById("elementID").createTextRange( );
		}
 
Value

Boolean value: true | false.

 
Default

Element default.

noWrapNN n/a IE 4 DOM 1  

Read/Write  

Specifies whether the browser should render the body content as wide as necessary to display a line of nonbreaking text on one line. Abuse of this attribute can force the user into a great deal of inconvenient horizontal scrolling of the page to view all of the content.

 
Example
 
document.body.noWrap = "true";
 
Value

Boolean value: true | false.

 
Default

false

recordNumberNN n/a IE 4 DOM n/a  

Read-only  

Used with IE data binding, returns an integer representing the record within the data set that generated the element (i.e., an element whose content is filled via data binding). Values of this property can be used to extract a specific record from an Active Data Objects (ADO) record set (see recordset property). Although this property is defined for all IE element objects, the other properties related to data binding belong to a subset of elements.

 
Example
 
<script for="tableTemplate" event="onclick">
		    myDataCollection.recordset.absoluteposition = this.recordNumber;
		    ...
		</script>
 
Value

Integer.

 
Default

null

rightMarginNN n/a IE 4 DOM n/a  

Read/Write  

Provides the width in pixels of the right margin of the body element in the browser window or frame. By default, the browser inserts a small margin to keep content from abutting the right edge of the window (except on the Macintosh). Setting the property to an empty string is the same as setting it to zero.

 
Example
 
document.body.leftMargin = 16;
 
Value

Integer of pixel count.

 
Default

10 (Windows); 0 (Macintosh).

scrollNN n/a IE 4 DOM n/a  

Read/Write  

Specifies whether the window (or frame) displays scrollbars when the content exceeds the window size. If your document specifies a standards-compatible DOCTYPE definition (see Chapter 8), the scroll property does not respond to changes for the body element. Nor does the html element object gain this property, as Microsoft's developer documentation purports.

 
Example
 
document.body.scroll = "no";
 
Value

Not exactly a Boolean value. Requires one of the following string values: yes | no | auto.

 
Default

yes

scrollHeight, scrollWidthNN 7 IE 4 DOM n/a  

Read-only  

Originally implemented in IE 4 for elements that either scrolled or influenced an element's scroll (body, button, caption, div, fieldset, legend, marquee, and textarea), these properties return the pixel dimensions of an element, including elements that are larger than the viewable area in the browser window. This is in contrast to the clientHeight and clientWidth properties for scrollable elements, which return dimensions of only visible portions of the element. IE for the Macintosh, however, interprets the intent of the scroll- properties differently, returning the dimensions of the visible portion.

 

Starting in IE 5 for Windows, all HTML elements have these properties, and the values for nonscrolling elements are the same as the offsetHeight and offsetWidth properties. Netscape 7 implements these properties for all elements, returning the height and width of the element, whether or not it's in view. The important point is that for key elements, such as the body, the properties mean different things and can disrupt cross-platform operation.

 
Example
 
var midPoint = document.body.scrollHeight/2;
 
Value

Positive integer or zero.

 
Default

None.

scrollLeft, scrollTopNN 7 IE 4 DOM n/a  

Read/Write  

Provide the distance in pixels between the actual left or top edge of the element's physical content and the left or top edge of the visible portion of the content. Setting these properties allows you to use a script to adjust the scrolling of content within a scrollable container, such as text in a textarea element or an entire document in the browser window or frame. When the content is not scrolled, both values are zero. Setting the scrollTop property to 15 scrolls the document upward by 15 pixels in the window; the scrollLeft property is unaffected unless explicitly changed. The property values change as the user adjusts the scrollbars. This is important for some event-driven positioning tasks in IE for Windows because the coordinate system for event offset measurements are with respect to the visible area of a page in the browser window. You must add document.body scrolling factors to align event coordinates with body content positions (see the element dragging example in Chapter 6). Starting with IE 5 for Windows, the scrollLeft and scrollTop properties are available for all HTML element objects, but values for unscrollable elements are zero.

 
Example
 
document.body.scrollTop = 40;
 
Value

Positive integer or zero.

 
Default

0

tabIndexNN 6 IE 4 DOM 1  

Read/Write  

This is a number that indicates the sequence of this element within the tabbing order of all focusable elements in the document. Tabbing order follows a strict set of rules. Elements that have values other than zero assigned to their tabIndex properties are first in line when a user starts tabbing in a page. Focus starts with the element with the lowest tabIndex value and proceeds in order to the highest value, regardless of physical location on the page or in the document. If two elements have the same tabIndex values, the element that comes earlier in the document receives focus first. Next come all elements that either don't support the tabIndex property or have the value set to zero. These elements receive focus in the order in which they appear in the document.

 

The W3C DOM and Netscape 6 limit the tabIndex property to the following element objects: a, area, button, input, object, select, textarea. To this list, IE 4 adds applet, body, div, embed, isindex, marquee, span, table, and td. IE 5 adds every other renderable element. A negative value in IE (only) removes an element from tabbing order entirely.

Links and anchors cannot be tabbed to with the Mac version of IE 4, so the tabIndex property for a element objects is ignored in that version.

 
Example
 
document.getElementById("link3").tabIndex = 6;
 
Value

Integer.

 
Default

0

textNN 6 IE 4 DOM 1  

Read/Write  

Indicates the color of text for the entire document body. Equivalent to the foreground color.

 
Example
 
document.body.text = "darkred";
 
Value

A hexadecimal triplet or plain-language color name. See Appendix A for acceptable plain-language color names.

 
Default

Browser default (user customizable).

topMarginNN n/a IE 4 DOM n/a  

Read/Write  

Provides the width in pixels of the top margin of the body element in the browser window or frame. By default, the browser inserts a small margin to keep content from abutting the top edge of the window. Setting the property to an empty string is the same as setting it to zero.

 
Example
 
document.body.topMargin = 16;
 
Value

Integer of pixel count.

 
Default

15 (Windows); 8 (Macintosh).

createTextRange( )NN n/a IE 4(Win) DOM n/a  

  

Creates a TextRange object from the rendered text content of the current element. See the TextRange object for details.

 
Parameters

None.

 
Returned Value

TextRange object.

clientLeft, clientTopNN n/a IE 4 DOM n/a  

Read-only  

Broadly speaking, these provide the left and top coordinates of the element's content within the box that includes the element's padding, but with minor variations among various operating system versions of IE. Not available for all element types in IE for Macintosh. See the Section 9.2 at the beginning of this chapter for details. More useful information for inline element positioning generally comes from the offsetLeft and offsetTop properties (including Netscape 6). For CSS-positioned elements (including changing an element's position), use style object properties, such as left and top, and (in IE only) pixelLeft and pixelTop.

 
Value

Integer pixel value.

 
Default

0