JavaScript Remove Focus
In this section, you will learn how to remove focus from the window using JavaScript.
To remove the focus from the window, we have used blur() method of the Window object. It removes the focus from a window and moves it behind other windows. Now, to explain it more clearly, we have also used the focus() method of Window object which sets the focus to the specified window in front of other windows. When you load the 'removeFocus.html' code, you will get a button 'Set Focus'. On clicking the button, the setFocus() function is called and a new window will get open but the focus is on the 'removeFocus.html' page as we have used the method window.focus(). But on clicking the button 'Remove Focus' from the 'hello.html' page, the removeFocus() function is called and the focus will lost from the current window i.e. hello.html due to the window.blur() method and hence focus gets back to the 'removeFocus.html'.
Here is the code of removeFocus.html:
| <html> <h2>Set Focus</h2> <script type="text/javascript"> function setFocus(){ window.open("hello.html"); window.focus(); } </script> <button onclick="setFocus()">Set Focus</button> </html> |
Here is the code of hello.html:
| <html> <h2>Remove Focus</h2> <script> function removeFocus(){ window.blur(); } </script> <button onclick="removeFocus()">Remove Focus</button> </html> |
Output will be displayed as:

On clicking the button 'Set Focus', a 'hello.html' page will get open:
On clicking the button 'RemoveFocus' , you will move back to the 'removeFocus.html'
Tutorials
- Java 26 (JDK 26) Features with examples
- Top 10 Reasons to Learn Java in 2026
- JDK 26 Tutorial
- Java Certification Roadmap 2026: Which Oracle Certs Matter
- Install JDK 26: A Complete Beginner's Guide (2026)
- What Is Java? A Complete, Up-to-Date Guide for 2026
- Java 26 HTTP3 tutorial - HTTP 3 support in JDK 26 - How to use HTTP/3 in Java 26 application?
- JDK 28 Preview: Value Objects, Shenandoah GC & JSON API
- Java Tutorials


