The
object contains the HTML document and has top-level events that make sense for this purpose:window
Event | Description |
|
Fired when the window object loses the focus |
|
Fired when the window object gains the focus |
|
Fired when the user presses the F1 or Help key |
|
Fired before the browser window is closed |
|
Fired when the browser window is resized |
|
Fired when the HTML text for the page has finished loading |
|
Fired just before the page is unloaded |
|
Fired when the user scrolls a page or element |
|
Fired when an error occurs loading a document or image |
These events are very useful for executing any code that needs to coincide with the loading or unloading of the browser.
is fired when the HTML for the current page has been downloaded, but may fire before all images, controls, or applets have finished loading.onLoad
The
event is not only fired before the browser navigates to a new page, but also immediately before the browser is shut down (which is understandable, because the page is indeed being unloaded in preparation for application shutdown).onUnload
Finally,
, fires before the page is unloaded. This event is only used during data binding and it allows you to validate entries in a field, before they're sent to a server, or pop a message box up. Its uses are discussed in the data binding section of the book in chapter 8.onBeforeUnload
When the user of the browser switches to another application or instance of IE4,
is fired. Any code placed in this event will be executed before the switch to the new window is made. The converse of onBlur
is onBlur
. This event is fired in the current browser when the user switches back to the browser window from another application. While onFocus
and onFocus
existed in the Internet Explorer 3.0 object model for some form elements, their appearance in the object definition for the onBlur
object didn't happen until IE4.window
This event is rather simple compared to some of the other events we've just finished considered. When the browser window is resized, this event is fired.
If a user presses F1 (or another key that happens to be mapped to online help), the window's
event is fired. This gives the developer control over what will happen if a person browsing their page requests help. The code for this event could redirect the user to one or more help pages on the same or another server on the internet/intranet. The new page can be displayed in a new window, in a modal dialog, or in the same browser window by using the onHelp
, open
, or showModalWindow
methods of the navigate
object, respectively.window
If not all of the display is visible to the user, and the user has to scroll the display to view it, in its entirety then an
event is generated.onscroll
This is perhaps one of the most useful events. It can be used if an error occurs during the download of a page or image. It can be used to determine whether an error occurred to the connection or whether the download was actually aborted. The user can allow for this eventuality within script and decide whether to get the script to try and download the information again, or display an appropriate message and take corrective action.