How to use Javascript Window Blur() and Window Focus() Method

Javascript Blur() method is used to remove focus from the current window. i.e, It sends the new open Window to the background.If click on the blur window button then the site.org page will move to the background. Whereas Javascript focus() method is used to focus on the new open window. i.e bringing back the blurred window to the foreground.

Below examples illustrate the window.blur() method of JavaScript:

Example: The below example illustrates the window.blur() method in JavaScript:

 var Window;
         
        // Function that open the new Window
        function windowOpen() {
          Window = window.open(
          "https://www.geeksforgeeks.org/",
            "_blank", "width=400, height=450 top=75");
        }
         
        // function that Closes the open Window
        function windowClose() {
          Window.close();
        }
         
        //function that focus on open Window
        function windowFocus() {
          Window.focus();
        }

Javascript Window.focus() method is used to focus on the new open window. i.e bringing back the blurred window to the foreground. 

 var Window;
         
        // Function that open the new Window
        function windowOpen() {
          Window = window.open(
          "https://www.geeksforgeeks.org/",
            "_blank", "width=400, height=450 top=75");
        }
         
        // function that Closes the open Window
        function windowClose() {
          Window.close();
        }
         
        //function that focus on open Window
        function windowFocus() {
          Window.focus();
        }

Leave a comment

Your email address will not be published. Required fields are marked *