views:

22

answers:

1

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?

+1  A: 

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;
    });
});
patrick dw