X
HOME HTML CSS JAVASCRIPT SQL PHP JQUERY ANGULAR XML ASP.NET MORE...
REFERENCES | EXAMPLES | FORUM | ABOUT

Window focus() Method

Window Object Reference Window Object

Example

Assure that the new window GETS focus (send the new window to the front):

var myWindow = window.open("", "", "width=200, height=100");   // Opens a new window
myWindow.document.write("<p>A new window!</p>");         // Some text in the new window
myWindow.focus();                                     // Assures that the new window gets focus

Try it yourself »


Definition and Usage

The focus() method sets focus to the current window.

Tip: Use the blur() method to remove focus from the current window.

Note: This method makes a request to bring the current window to the foreground. It may not work as you expect in all browsers, due to different user settings.


Browser Support

Internet Explorer Firefox Opera Google Chrome Safari

The focus() method is supported in all major browsers.


Syntax

window.focus()

Parameters

None.

Return Value

No return value.


More Examples

Example

Assure that the new window does NOT get focus (send the new window to the background):

var myWindow = window.open("", "myWindow", "width=200, height=100");
myWindow.document.write("<p>This is 'myWindow'</p>");
myWindow.blur();  // Assures that the new window does NOT get focus);

Try it yourself »


Window Object Reference Window Object

Your suggestion:

Close [X]

Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]
Search w3schools.com:

WEB HOSTING

UK Reseller Hosting

WEB BUILDING

Download XML Editor FREE Website BUILDER Free HTML5 Templates FREE Website Templates Free HTML Templates

SHARE THIS PAGE

facebook