history, screen, and navigator

The remaining three objects that are direct children to the window object are history, screen, and the navigator. Between these three, you’ll have a good idea of what kind of browser is accessing the page, and how much space you have in which to work. You’ll also be able to send your web-page readers on their way using the history object.

As these objects are fairly simple in functionality and single-purposed, I’ll review each, in turn, and then provide one example for all three at the end of this section.


The history object is just as it sounds: it maintains a history of pages loaded into the browser. As such, its methods and properties have to do with navigation through these pages, including going forward and back.

You can traverse through history using relational properties, such as next and previous, or using the methods back and forward. You can find the current page with current, and get the length of history (number of pages stored in the history cache). You can also go to a specific page using the go method and passing in a page number—negative to go backward that many pages:


And positive to go forward:


history, as they say, takes care of itself; you as page developer don’t have to worry overmuch about it. About the only time when history becomes a concern is when using in-page techniques such as DHTML and Ajax, which work outside the normal patterns of page loading. However, we’ll get into these ...

Get Learning JavaScript now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.