400 Part III (Web hosting script) . Document Objects Reference About

January 24th, 2008

400 Part III . Document Objects Reference About this object In object models that reveal HTML element objects, the BODY element object is the primary container of the content that visitors see on the page. The BODY contains all rendered HTML. This special place in the node hierarchy gives the BODY object some special powers, especially in the IE object model. As if to signify the special relationship, both the IE and W3C object models provide the same shortcut reference to the BODY element: document.body. As a first- class HTML element object (as evidenced by the long lists of properties, methods, and event handlers covered in Chapter 15), you are also free to use other syntaxes to reach the BODY element. You are certainly familiar with several BODY element attributes that govern body-wide content appearance, such as link colors (in three states) and background (color or image). But IE and NN (and the W3C so far) have some very different ideas about the BODY element s role in scripting documents. Many methods and properties that NN considers to be the domain of the window (for example, scrolling, inside window dimensions, and so forth), IE puts into the hands of the BODY element object. Therefore, while NN scrolls the window (and whatever it may contain), IE scrolls the body (inside whatever window it lives). And because the BODY element fills the entire viewable area of a browser window or frame, that viewable rectangle is determined in IE by the body s scrollHeightand scrollWidth properties, whereas NN4+ features window.innerHeight and window.innerWidth properties. This distinction is important to point out because when you are scripting window- or document-wide appearance factors, you may have to look for properties and methods for the window or BODY element object, depending on your target browser(s). Note Use caution when referencing the document.body object while the page is loading. The object may not officially exist until the page has completely loaded. If you need to set some initial properties via scripting, do so in response to the onLoad event handler located in the tag. Attempts at setting BODY element object properties in immediate scripts inside the HEAD element may result in error messages about the object not being found. Properties aLink bgColor link text vLink Value: Hexadecimal triplet or color name string Read/Write document.body.aLink
Visit our web design programs services for an affordable and reliable webhost to suit all your needs.

399Chapter 18 .The Document and Body Objects On

January 23rd, 2008

399Chapter 18 .The Document and Body Objects On the Example on the CD with Listing 18-19 CD-ROM Related Items: Repeat loops (Chapter 39). BODY Element Object For HTML element properties, methods, and event handlers, see Chapter 15. Properties Methods Event Handlers alink createControlRange() onAfterPrint background createTextRange() onBeforePrint bgColor doScroll() onScroll bgProperties bottomMargin leftMargin link noWrap rightMargin scroll scrollLeft scrollTop text topMargin vLink Syntax Accessing BODY element object properties or methods: [window.] document.body.property | method([parameters]) NN2 NN3 NN4 NN6 IE3/J1 IE3/J2 IE4 IE5 IE5.5 Compatibility . . document.body
We highly recommend you visit web and email hosting services if you need stable and cheap web hosting platform for your web applications.

398 Part III . Document (Web server certificate) Objects Reference The

January 23rd, 2008

398 Part III . Document Objects Reference The other image trick is to be sure to specify HEIGHTand WIDTH attributes for every image, scripted or otherwise. Navigator 2 requires these attributes (as does the HTML 4.0 specification), and document-rendering performance is improved on all platforms, because the values help the browser lay out elements even before their details are loaded. In addition to the document.write()example that follows (see Listings 18-16 through 18-18), you can find fuller implementations that use this method to assemble images and bar charts in many of the applications in Chapters 48 through 57. Because you can assemble any valid HTML as a string to be written to a window or frame, a customized, on-the-fly document can be as elaborate as the most complex HTML document that you can imagine. On the CD-ROM Example on the CD with Figure 18-2 and Listings 18-16, 18-17, and 18-18 Related Items: document.open(); document.close(); document.clear() methods. Event handlers onSelectionChange NN2 NN3 NN4 NN6 IE3/J1 IE3/J2 IE4 IE5 IE5.5 Compatibility . The onSelectionChange event can be triggered by numerous user actions, although all of those actions occur on elements that are under the influence of the IE5.5/Windows edit mode. Related Items: onControlSelect event handler. onStop NN2 NN3 NN4 NN6 IE3/J1 IE3/J2 IE4 IE5 IE5.5 Compatibility . The onStop event fires in IE5 when the user clicks the browser s Stop button. Use this event handler to stop potentially runaway script execution on a page, because the Stop button does not otherwise control scripts after a page has loaded. If you are having a problem with a runaway repeat loop during development, you can temporarily use this event handler to let you stop the script for debugging. document.onStop
If you are looking for affordable and reliable webhost to host and run your business application visit our ftp web hosting services.

397Chapter 18 .The Document and Body Objects document.write() (Free web space)

January 22nd, 2008

397Chapter 18 .The Document and Body Objects document.write() statement. Also be sure to include a document.close()statement in the next line of script. Assembling HTML in a script to be written via the document.write() method often requires skill in concatenating string values and nesting strings. A number of JavaScript String object shortcuts facilitate the formatting of text with HTML tags (see Chapter 34 for details). If you are writing to a different frame or window, you are free to use multiple document.write() statements if you like. Whether your script sends lots of small strings via multiple document.write() methods or assembles a larger string to be sent via one document.write() method depends partly on the situation and partly on your own scripting style. From a performance standpoint, a fairly standard procedure is to do more preliminary work in memory and place as few I/O (input/output) calls as possible. On the other hand, making a difficult-to-track mistake is easier in string concatenation when you assemble longer strings. My personal preference is to assemble longer strings, but you should use the system that s most comfortable for you. You may see another little-known way of passing parameters to these methods. Instead of concatenating string values with the plus (+) operator, you can also bring string values together by separating them with commas. For example, the following two statements produce the same results: document.write( Today is + new Date()) document.write( Today is ,new Date()) Neither form is better than the other, so use the one that feels more comfortable to your existing programming style. Note Dynamically generating scripts requires an extra trick, especially in NN. The root of the problem is that if you try code, such as document. write( ), the browser interprets the end script tag as the end of the script that is doing the writing. You have to trick the browser by separating the end tag into a couple of components. Escaping the forward slash also helps. For example, if you want to load a different .js file for each class of browser, the code looks similar to the following: // variable browserVer is a browser-specific string and // page is the HTML your script is accumulating for document.write() page +=