Is there an event that I can register for that fires each time the user clicks on a tab, meaning that they were on my page's tab, clicked on another tab, then came back to my tab.
EDIT: By tabs, I mean browser tabs, not jQueryUI tabs.
Detect tab changes with JavaScript To detect the tab change we use pure JavaScript without jQuery etc. Everything you need is hidden in this code. We register the blur event on the global document variable. Generally, the blur and focus events are often used in conjunction.
Use the visibilitychange event to detect if a browser tab has focus or not, e.g. document. addEventListener('visibilitychange', checkTabFocused) . The event is fired at the document when the contents of its tab have become visible or have been hidden.
var selectedTab = $("#TabList"). tabs(). data("selected. tabs");
jQuery focus() MethodThe focus event occurs when an element gets focus (when selected by a mouse click or by "tab-navigating" to it). The focus() method triggers the focus event, or attaches a function to run when a focus event occurs. Tip: This method is often used together with the blur() method.
Matijis provided this answer in a comment, but I wanted to accept it so here it is as an answer.
$(window).on('focus', function() { // your code });
Try using jquery $(selector).focusin or :focus, they both work quite the same way.
http://api.jquery.com/focusin/
http://api.jquery.com/focus-selector/
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