1. Home
  2. Computing & Technology
  3. JavaScript

Browser Object Model

The Browser Object Model is the one part of JavaScript for which no formal standards exist. It is also the part that is generally the least useful and the part which newbies most want to work with. We'll look first at those objects that all browsers define starting with the most useful and then move on to how to handle the situations where different browsers provide different ways to access the same information.

Introduction

Just what is the Browser Object Model and how does it fit with the rest of JavaScript.

window

The window object is the most useful part of the Browser Object Model. In fact you can't use JavaScript in a web browser without it.

Timeouts and Intervals

Building delays into your JavaScript processing in order to produce animated effects is another useful process performed by the Browser Object Model.

window.document

Not all of the properties and methods attached to the document belong to the Document Object Model, some of them are part of the Browser Object Model and some of those may occasionally be of use.

location

window.location provides everything that window.document.url does and much more.

history

The history object provides the ability to move to different pages in the browser history but its use is limited because you can't see what is actually in the history, just how many pages are in the history.

Manipulating Windows

Now that we have tabbed browsers the ability to open, move, and resize windows from JavaScript is less useful than it used to be since our visitors can always override our suggestions and open our new page in a new tab instead.

The Screen

The size of your visitor's screen is not a very useful piece of information. Fortunately browsers provide a way to find out what space is left after taking fixed toolbars into account. The information is still only useful for when your visitor allows you to open a new window though.

navigator

The navigator object is the least useful of the BOM objects out of those available on all browser. Different browsers implement different properties on this object to hold the same information making it necessary to test multiple properties to see which is supported and with those that are commonly supported the content is free format user enterable data.

Viewport Size

Moving on from common but not very useful BOM objects and the most useful BOM data that needs to be accessed in different ways depending on the browser is the available width and height in the viewport. All of your animations will need this information so as to know how far they can move while remaining visible.

Mouse Position

Most browsers provide a way to retrieve the coordinates of where the mouse cursor is pointing within the page - they just don't provide the same way of accessing it. We can set up simple functions to provide common calls that we can use that work cross browser.

Scroll Position

The distance that the current page has been scrolled in the browser viewport is yet another pair of values where we require functions to provide us with cross browser support. Most do support a common call to actually scroll the page to a specified location.
Explore JavaScript
About.com Special Features

Holiday Central

What to eat, where to go, fun things to do and how to save money on the perfect gifts. More >

Family Tech Center

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

  1. Home
  2. Computing & Technology
  3. JavaScript
  4. Javascript Tutorials
  5. Browser Object Model

©2009 About.com, a part of The New York Times Company.

All rights reserved.