Event when a web page gets focused
Try using jQuery's focus
and blur
functions:
$(window).focus(function() {
console.log('welcome (back)');
});
$(window).blur(function() {
console.log('bye bye');
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
Click in and out of this frame to test the focus and blur functions.
I tested in FF and document.onfocus
is called when I switch to that window.