The window Object

The browser window encompasses the entire browser environment, including parts of the window “chrome” (the part of the browser that surrounds the document), the actual web page, and even the user’s experiences.

The window object is global and always present even if its presence is implicitly, rather than explicitly, stated. In previous chapters we’ve used functions such as alert and eval, and these functions may seem “independent” of any object model. However, they’re implicitly a part of the window object—as is the document and other second-level objects, global variables, and other objects not associated with any other object within an object model.

The window has interest beyond being just a parent to all other elements. Through it you can manually set the status in the status bar of the browser, open a new window, resize one that’s already open, and then close it again. This is handy if you’re providing separate windows for help or additional information, though with the growing popularity of DHTML and Ajax, much of this now occurs within a document rather than a separate window.

The window object methods and properties fall into four categories: creating and managing new windows, manipulating the behavior of existing windows, serving as timers, and being the parent of the other objects in the BOM.

For the first category, creating new windows, three methods provide quick pop-up windows (each for a specific purpose), while a fourth can create ...

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.