I have this:
$(window).blur(function() {
setInterval(function() {
$.ajax({
type: "POST",
url: "imback.php",
data: {
mode: 'ajax',
getUpdates: 'auto',
},
success: function(msg){
document.title = msg + titleOrig;
}
});
}, 35000);
Works fine.
Although, if you have been blur, and then when you focus back, it will keep making the ajax call, it doesnt stop sending ajax call after interval 35 seconds.
How can i fix this?
})
You need to store the interval when you set it, and then clear it on window focus. Like this:
EDIT: I added
(function() { ... })()around the code to encapsulate the “interval” variable, essentially making it “private” to the window blur and focus handlers.