Window focus () method
Definition and Usage
focus () method to give the keyboard focus a window.
grammar
window.focus()
Browser Support
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>
<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"
More examples
Ensure that the new window does not get focus
Window object