window.focus()

JavaScript1.1+, JScript1.0+ Nav3+, IE3+, Opera3+ Syntax

							window.focus()

Description

The focus() method of the Window object places focus on the window. Be careful when using this method in conjunction with the blur() method of objects. It can lead to a focus/blur loop, where the browser blurs a focus as soon as it is done, and vice versa.

Example

Listing 7.539 has a button. When the user clicks the Open button, a second, smaller window is opened and the focus is placed back on the parent window.

Listing 7.539 Using the focus() Method to Remove the Focus from a Window
 <html> <head> </head> <script language="JavaScript1.1"> <!-- Hide // Define the openWin() function function openWin(){ // Create variables to hold the various ...

Get Pure JavaScript 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.