Latest web development tutorials

Window focus () method

Window Object Reference Window object

Definition and Usage

focus () method to give the keyboard focus a window.

grammar

window.focus()


Browser Support

Internet ExplorerFirefoxOperaGoogle ChromeSafari

All major browsers support focus () method


Examples

Examples

Ensure that the new window receives focus (before sending a new window):

<! DOCTYPE html>
<Html>
<Head>
<Meta charset = "utf-8">
<Title> This tutorial (w3big.com) </ title>
<Script>
function openWin () {
myWindow = window.open ( '', '', 'width = 200, height = 100');
myWindow.document.write ( "<p> This is 'my window' </ p>");
myWindow.focus ();
}
</ Script>
</ Head>
<Body>

<Input type = "button" value = "open window" onclick = "openWin ()" />

</ Body>
</ Html>

try it"


Examples

More examples

Ensure that the new window does not get focus


Window Object Reference Window object