Attributes for <BODY ...>
onFocus = "script command(s)"
onBlur = "script command(s)"
onFocus is the event handler for when the body of the page receives the focus.
onBlur is the event handler for when the body loses the focus. For example, the following code puts "focused" in the status bar when the page receives the focus, and "not focused" when it loses the focus.
this code |
produces this |
<BODY
onFocus="window.status='focused'"
onBlur="window.status='not focused'">
|
this page |
There is some difference in how browsers trigger the onFocus event. If the page is not framed, MSIE triggers onFocus when the page is loaded. Netscape, on the other hand, only triggers onFocus if the user actually clicks on the page.
If the page is framed, MSIE and Netscape are relatively consistent with each other. They both trigger onFocus for each framed page when the user clicks on the page. For example, suppose you want the frame that has the focus to change to rad while the other are white. To do this, you could put the following script into the
<HEAD> of each page:
<SCRIPT TYPE="text/javascript">
<!--
function setbg(color)
{
document.bgColor=color;
document.body.style.backgroundColor=color;
}
//-->
</SCRIPT>
Then you could call this script with onFocus and onBlur
event handlers like this:
<BODY onFocus="setbg('red')" onBlur="setbg('white')">
That gives us the events on this page.
The body loses the focus when objects inside the body get the focus. So, for example, onBlur is triggered when the user clicks into a form element, such as in this page.
|