Is there a way, using JavaScript or jQuery, to detect when someone goes back to your page after opening a new window or tab?
I want to create a script that opens a new window or tab, and then does something when the user comes back to the page.
Thanks,
yes, there is. Using jQuery:
$(window).bind('focusout', function(){
console.log('bye bye');
});
$(window).bind('focusin', function(){
console.log('welcome back!');
});
edit 1
Using alert()
was not the best idea there :p Changed to console.log()
for demonstration.
edit 2
binding to document
does not work crossbrowser, changed to window
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With