Javascript Browser Window focus() Method

Introduction

Click the button to open a new window, and assure that the new window GETS focus.

View in separate window

<!DOCTYPE html>
<html>
<body>
<button onclick="myFunction()">Test</button>

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

</body>
</html>

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

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

window.focus();



PreviousNext

Related