Status Property in JavaScript

Information - The Status Property

Information can be written in the status bar using the status property of a browser window.

The Default Status Message

To write a message in the status bar that remains visible until it is changed, a function is not needed. The script below illustrates how this is done. This might be appropriate for a course Home Page.

<script language="JavaScript">
<!--
window.defaultStatus="Welcome to Chemistry 101";
// -->
</script>

Changing the Status Message

The status property can be changed as the result of some user action such as onclick or onmouseover. Changing the status message requires a function. The function below writes a message, "A good site for examples" to the status bar, after an event has occured.

<script language="JavaScript">
<!--
function changeTheStatus() {
window.status="A good site for examples";
}

// -->
</script>

The function below writes " ", an empty space, to the status bar after an event has occured.

<script language="JavaScript">
<!--
function removeStatus() {
window.status=" ";
}

// -->
</script>

You can combine both functions in one script, along with an event that triggers the functions.


Exercise

1. Type the script below in using Notepad.
2. Save on the desktop with an .HTM or .HTML extension.
3. Double click the file name to open in your browser.
4. If there are no mistakes, your web page should look like this.

<html>
<head>
<title>Change the Status Bar</title>

<script language="JavaScript">
function changeTheStatus() {
window.status="A good site for examples.";
}

function removeStatus() {
window.status=" ";
}

</script>
</head>
<body>
<a href="http://www.yahoo.com" onMouseOver="changeTheStatus(); return true" onMouseOut="removeStatus()">The Yahoo Site</a>
</body>
</html>