check js if clicked on active tab code example
Example: if browsertab is active jquery
document.addEventListener('visibilitychange', function() {
if(document.hidden)
console.log('Page is hidden from user view');
else
console.log('Page is in user view');
});