asp.net.ph

Skip Navigation LinksHome > Abakada: Back to Basics > Dynamic HTML > Working with Windows and Frames

Dynamic HTML

Abakada ~ Back to Basics


Using the Window Object

The window object represents the browser window that contains the HTML document. The browser window is typically accessed in client-side script using the following notation.

window.property

or

window.method ( ) 

The window keyword before the property or method may be omitted if the current window object is implied. Most authors, however, prefer to use the window prefix to ensure that their scripts are as clear and readable as possible.

The window object includes a generic set of properties which can be used to set or retrieve the values of certain window features or characteristics.

For example, to change the text in the browser status bar, we use the window status property:

window.status = "Welcome to the Web WorkShop.";

which can be shortened as in the following, if you are referring to the current window object:

status = "Welcome to the Web WorkShop.";

To see this in action, look at the status bar of this window, which shows the title of the current document.

The window object also includes a generic set of methods which can be used to carry out simple tasks, such as displaying messages, prompting for input, and loading new documents into the window.

For example, to display a simple message box from the current window, we use the alert method:

alert ( "Welcome to the Web WorkShop." );

Now, putting together what we've learned so far, here is a sample that displays an alert box and changes the text in the status bar when a page loads.

<html>
<head>
<title>A Sample Document</title>

<script language="JavaScript">
<!—
function doAlert ( ) {
   window.status = "Page is loaded!";
   alert ( "Page is loaded!" );
}
//—>
</script>
</head>

<body onload="doAlert ( )">
   ... document content here ...
</body>
</html>

 Show me 

More ...
Back to top


© 2025 Reynald Nuñez and asp.net.ph. All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note