my goal is to auto-refresh some components with jquery when the “page tab” is focussed. I have a “sort of cart” and i want to auto-update it even if you are displaying my site from more than 1 tab.
Also, i’m trying to make it work from an iframe inside a page!
is this possible or i must use some timer to auto-refresh periodically?
edit: after reading the solution i made it work once for every focus, don’t know if it’s the best solution but it gets the job done 😀
var focusPage = false;
var firstFocus = false;
$(window).focus(function () {
focusPage = true;
if (firstFocus) {
firstFocus = false;
//BAM! Refresh your stuff
}
});
$(window).blur(function () {
focusPage = false;
firstFocus = true;
});
Using this seems to work well: