Chapter 8. Browser Pieces
8.0. Introduction
The browser objects include the window, navigator, screen, history, and location. They’re part of what is known as the
Browser Object Model (BOM), or the DOM Level 0 set of
objects, which also includes the document, frames, and various other elements.
Typically though, when we think of browser objects, we think of the first
five elements I just mentioned. In the HTML5 specification, these are
known as the browsing context.
The topmost element is the window, and all the other
browser objects are children. You can access the children elements using
the window:
var browser = window.navigator.userAgent;
Or you can access the objects directly:
var browser = navigator.userAgent;
When working with the browser objects, be aware that until very recently, none of the objects was covered by a standard specification, and a consistent implementation was not guaranteed. Though most browsers share the same methods and properties, there are also browser-specific properties with each object. Make sure to check your target browsers’ documentation when you work with the objects, and test the pages in all of the browsers.
Work is underway with the W3C HTML5 effort to provide a user application object model, which does include all of the browser objects covered in this chapter. However, it’s all very new, and not broadly implemented at the time of this writing. It’s also subject to change, since the HTML5 effort is still ongoing. Where possible, I’ll note how an ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access