Window.focus()

Makes a request to bring the window to the front. It may fail due to user settings and the window isn't guaranteed to be frontmost before this method returns.

Syntax

window.focus() 

Example

if (clicked) { window.focus(); }

Specification

Specification Status Comment
HTML Living Standard
The definition of 'Window.focus()' in that specification.
Living Standard

Browser compatibility

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
focusChrome Full support 1
Notes
Full support 1
Notes
Notes Starting in Chrome 66, opening a popup in fullscreen mode and calling this function will end fullscreen mode.
Edge Full support 12Firefox Full support 1IE Full support 4Opera Full support ≤12.1Safari Full support 1WebView Android Full support 1Chrome Android Full support 18Firefox Android Full support 4Opera Android Full support ≤12.1Safari iOS Full support 1Samsung Internet Android Full support 1.0

Legend

Full support  
Full support
See implementation notes.
See implementation notes.