'Multi tab event sharing with javascript
My scenario is: Multiple copies of same web application is open on multiple tab of same browser. I go to one of the tab. I click on a button present of page and on click of that button it registers focus event on window.
$('#btn').click(function(event){
if (/*@cc_on!@*/false) {
document.addEventListener("focusin", onFocus,false);
} else {
window.addEventListener("focus", onFocus,false);
}
function onFocus(){$
//Reload Page if logged out$
window.location.reload();$
};$
It is expected that when I switch to other tabs and page should get reloaded.
Problem is that page on other is not reloading.
Solution 1:[1]
If I add listener at page load then it works.
$(document).ready(function(){
if (/*@cc_on!@*/false) { // check for Internet Explorer
document.addEventListener("focusin", onFocus,false);
} else {
window.addEventListener("focus", onFocus,false);
}
return true;
});
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Ajinkya Pisal |
