15.02.2013 Views

JavaScript Examples Bible - UserWorks Technologies

JavaScript Examples Bible - UserWorks Technologies

JavaScript Examples Bible - UserWorks Technologies

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 4 ✦ The Document and Body Objects (Chapter 18)<br />

Example<br />

Use The Evaluator (Chapter 13 in the <strong>JavaScript</strong> <strong>Bible</strong>) to experiment with the<br />

defaultCharset property. To see the default setting applied to the page, enter the<br />

following statement into the top text box:<br />

document.defaultCharset<br />

documentElement<br />

NN2 NN3 NN4 NN6 IE3/J1 IE3/J2 IE4 IE5 IE5.5<br />

Compatibility ✓ ✓ ✓<br />

Example<br />

Use The Evaluator (Chapter 13 in the <strong>JavaScript</strong> <strong>Bible</strong>) to examine the behavior<br />

of the documentElement property. In IE5+ or NN6, enter the following statement<br />

into the top text field:<br />

document.documentElement.tagName<br />

The result is HTML, as expected.<br />

expando<br />

NN2 NN3 NN4 NN6 IE3/J1 IE3/J2 IE4 IE5 IE5.5<br />

Compatibility ✓ ✓ ✓<br />

Example<br />

Use The Evaluator (Chapter 13 in the <strong>JavaScript</strong> <strong>Bible</strong>) to experiment with the<br />

document.expando property in IE4+. Begin by proving that the document object<br />

can normally accept custom properties. Type the following statement into the top<br />

text field:<br />

document.spooky = “Boo!”<br />

This property is now set and stays that way until the page is either reloaded or<br />

unloaded.<br />

Now freeze the document object’s properties with the following statement:<br />

document.expando = false<br />

If you try to add a new property, such as the following, you receive an error:<br />

document.happy = “tra la”<br />

Interestingly, even though document.expando is turned off, the first custom property<br />

is still accessible and modifiable.<br />

231<br />

document.expando

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!