1

How do I make an event listener that runs when you switch back to a window?

I've tried "focus", but it only runs when you click inside a form on the window. How do I make it run every time you tab back to the window?

Here's my current code I'm running:

<script type="text/javascript">
    document.addEventListener("focus", getURL, true);

    function getURL(){    
        //code
    }
    </script>
Jack Bashford
  • 43,180
  • 11
  • 50
  • 79
knat
  • 196
  • 1
  • 8

1 Answers1

1

Here's how you'd do it in jQuery:

$(window).blur(function(e) {
    // Do Blur Actions Here
});
$(window).focus(function(e) {
    // Do Focus Actions Here
});
Jack Bashford
  • 43,180
  • 11
  • 50
  • 79