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 ...

Get JavaScript and Ajax for the Web: Visual QuickStart Guide, Seventh Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.