开发者

jquery: How to know if a page is not in focus?

For example, if user is doing other things but not viewin开发者_如何学Pythong this page, jquery/javascript can know?

I don't need to be very accurate, just roughly.


You can try this:

$(window).focus(function(){
  // back in focus
});

And:

$(window).blur(function(){
  // no focus 
});


You might want to use a blur or focusout event on your document or window.

$(document).bind('focusout', function() {
    // window or tab just lost the focus
});

that's using jQuery. You should play around with this, also use the window object as target. I'm not super sure how cross-browser this works, but it should perform well.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜