Window focus() Method - Javascript Browser Object Model

Javascript examples for Browser Object Model:Window focus

Description

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

Parameters

None

Return Value

No return value

The following code shows how to Assure that the new window GETS focus (send the new window to the front):

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<button onclick="myFunction()">Test</button>

<script>
function myFunction() {//from  w ww  .  ja  v  a 2  s  .  co  m
    var myWindow = window.open("", "", "width=200,height=100");
    myWindow.document.write("<p>A new window!</p>");
    myWindow.focus();
}
</script>

</body>
</html>

Related Tutorials