Sams Teach Yourself JavaScript in 24 Hours
- Table of Contents
- Copyright
- About the Author
- Acknowledgments
- We Want to Hear from You!
- Reader Services
- Introduction
- Part I: Getting Started
- Hour 1. Understanding JavaScript
- Hour 2. Creating a Simple Script
- Hour 3. How JavaScript Programs Work
- Part II: Learning JavaScript Basics
- Hour 4. Using Functions and Variables
- Hour 5. Using Strings and Arrays
- Hour 6. Testing and Comparing Values
- Hour 7. Repeating Yourself: Using Loops
- Hour 8. Using Math and Date Functions
- Part III: The Document Object Model (DOM)
- Hour 9. Working with the Document Object Model
- Hour 10. Responding to Events
- Hour 11. Using Windows and Frames
- Hour 12. Getting Data with Forms
- Hour 13. Using Graphics and Animation
- Part IV: Moving on to Advanced JavaScript Features
- Hour 14. Creating Cross-Browser Scripts
- Hour 15. Creating Custom Objects
- Hour 16. Working with Sounds and Plug-Ins
- Hour 17. Debugging JavaScript Applications
- Part V: Working with Dynamic HTML (DHTML)
- Hour 18. Working with Style Sheets
- Hour 19. Using Dynamic HTML (DHTML)
- Hour 20. Using Advanced DOM Features
- Part VI: Putting It All Together
- Hour 21. Improving a Web Page with JavaScript
- Hour 22. Creating a JavaScript Game
- Hour 23. Creating DHTML Applications
- Hour 24. JavaScript Tips and Tricks
- Part VII: Appendices
- Appendix A. Other JavaScript Resources
- Appendix B. Tools for JavaScript Developers
- Appendix C. Glossary
- Appendix D. JavaScript Quick Reference
- Appendix E. DOM Quick Reference
- DOM Level 0
- DOM Level 1
DOM Level 0
The Level 0 DOM includes objects that represent the browser window, the current document, and its contents. The following is a basic summary of Level 0 DOM objects.
Window
The window object represents the current browser window. If multiple windows are open or frames are used, there may be more than one window object. These are given aliases to distinguish them:
- self represents the current window, as does window. This is the window containing the current JavaScript document.
- top is the window currently on top (active) on the screen.
- parent is the window that contains the current frame.
- The frames array contains the window object for each frame in a framed document.
The window object has three child objects:
- location stores the location (URL) of the document displayed in the window.
- document stores information about the current Web page.
- The history object contains a list of sites visited before or after the current site in the window.
Location
The location object contains information about the current URL being displayed by the window. It has a set of properties to hold the different components of the URL:
- location.hash is the name of an anchor within the document, if specified.
- location.host is a combination of the host name and port.
- location.hostname specifies the host name.
- location.href is the entire URL.
- location.pathname is the directory to find the document on the host, and the name of the file.
- location.port specifies the communication port.
- location.protocol is the protocol (or method) of the URL.
- location.query specifies a query string.
- location.target specifies the TARGET attribute of the link that was used to reach the current location.
History
The history object holds information about the URLs that have been visited before and after the current one in the window, and includes methods to go to previous or next locations:
- history.back goes back to the previous location.
- history.forward goes forward to the next location.
- history.go goes to a specified offset in the history list.
Document
The document object represents the current document in the window. It includes the following child objects:
- document.forms is a collection with an element for each form in the document.
- document.links is a collection containing elements for each of the links in the document.
- document.anchors is a collection with elements for each of the anchors in the document.
- document.images contains an element for each of the images in the current document.
- document.applets is a collection with references to each embedded Java applet in the document.
Navigator
The navigator object includes information about the current browser version:
- appCodeName is the browser's code name, usually "Mozilla."
- appName is the browser's full name.
- appVersion is the version number of the browser. (Example: "4.0(Win95;I)".)
- userAgent is the user-agent header, which is sent to the host when requesting a web page. It includes the entire version information, such as "Mozilla/4.5(Win95;I)."
- plugIns is a collection, which contains information about each currently-available plug-in (Netscape only).
- mimeTypes is a collection containing an element for each of the available MIME types (Netscape only).
DOM Level 1 | Next Section

Account Sign In
View your cart