Reputation: 18123
Hey, i wish to make an ajax call if it has lost the focus from my site for 1 minute, so when it's onfocus again it send an ajax call? How can i do that?
Upvotes: 1
Views: 781
Reputation: 322602
This seems to work. Give it a try:
$(function() {
var tracktime;
$(window).blur(function() {
tracktime = new Date();
})
.focus(function() {
if(tracktime && new Date() - tracktime > 60000) {
$.ajax({
url:'/your/path/',
success:function() {
alert('ajax returned')
}
})
}
tracktime = null;
});
});
Upvotes: 1