用户切换浏览器标签时的事件 [英] Event for when user switches browser tabs

查看:291
本文介绍了用户切换浏览器标签时的事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在寻找当用户从页面切换到另一个标签时触发的事件,以及当用户再次切换回标签页时触发的另一个事件。

I'm looking for an event which will fire whenever the user switches away from the page to another tab, and another event which fires when the user switches back to the tab again.

window.onblur和window.onfocus 似乎无法正常工作所有浏览器

window.onblur and window.onfocus don't seem to work correctly across all browsers

有没有代理我可以看看为了合成这个事件?

Is there a proxy I could look at in order to synthesize this event?

推荐答案

您可以尝试使用一个框架,如MooTools或jQuery,提供跨浏览器支持。他们应该能够更可靠地检测浏览器窗口的 blur 焦点事件。

You might try using a framework, such as MooTools or jQuery which provide cross-browser support. They should be able to detect with more reliability the blur and focus events for the browser window.

我个人使用jQuery取得了很大成功:

I personally have used jQuery with much success:

$(window).blur(function(e) {
    // Do Blur Actions Here
});
$(window).focus(function(e) {
    // Do Focus Actions Here
});

这篇关于用户切换浏览器标签时的事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆