The onfocus event

The onfocus and onblur handlers are mirror images of each other. While they may sound like what happens when you’ve been working on JavaScript too late at night, in reality, the onfocus handler triggers when a page becomes the front-most active window. Scripts 9.5 and 9.6 catch the onfocus handler and force the page to always go to the back (Figure 9.3).

Figure 9.3. The page in the back will stay there.


1.
window.onfocus = moveBack;



Here’s another example of the window and event handler object calling a function, in this case moveBack.

2.
function moveBack() {
  self.blur();
}



If the browser window becomes the active window, this function is triggered and forces the window to be blurred (i.e., inactive).

Script 9.5. This HTML is for the page that’s in back.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
     <title>Always in Back</title>
     <script type="text/javascript" src="script03.js"></script>
</head>
<body bgcolor="#FFFFFF">
     <h1>Unimportant content that should never be in front</h1>
</body>
</html>

Script 9.6. Using the onfocus handler, you can control window stacking.
window.onfocus = moveBack;
								function moveBack() {
								self.blur();
								}

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.141.104.97