The Browser Object

Finally, you should at least briefly consider the Browser Object Model or Browser Object. Using JavaScript, you can not only read and control the page and its contents, but also read and adjust properties of the browser displaying it. This can be in the form of resizing the window, or simply getting the value of the URI displayed in the address bar. Table 26-6 summarizes a few of the common properties and methods available to you in the Browser Object, which is accessed programmatically as window.

Table 26-6. Browser Object properties and methods

Property/method

Description

event

Represents the state of an event

history

Contains the URLs the user has visited within a browser window

location

Gives read/write access to the URI in the address bar

opener

Sets or returns a reference to the window that created the window

parent

Returns the parent window

screenLeft

Returns the x-coordinate of the upper-left corner of the browser relative to the upper-left corner of the screen

screenTop

Returns the y-coordinate of the top corner of the browser relative to the top corner of the screen

status

Sets or returns the text in the status bar of the window

alert( )

Displays an alert box with a specified message and an OK button

close( )

Closes the current window

confirm( )

Displays a dialog box with a specified message and an OK and a Cancel button

focus( )

Sets focus on the current window

open( )

Opens a new browser window

Get Web Design in a Nutshell, 3rd Edition 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.