在我的 window/tab 上是否有检测焦点和模糊的事件

Is there an event to detect focus and blur on my window/tab

有什么方法可以检测用户是否聚焦了我的页面?或者是否可以检测我的页面是否已打开但不在当前获得焦点的选项卡中?

jQuery .focusin() https://api.jquery.com/focusin/

类似的东西。

$(window).on('focus', function() { alert("focus") });

http://jsfiddle.net/5cLf0fn7/2/

阅读

GlobalEventHandlers.onfocus
GlobalEventHandlers.onblur
Window.focus()

JavaScript

window.onfocus = function() { console.log('Yeah, got focus'); }
window.onblur = function() { console.log('Yeah, lost focus'); }

演示

Try before buy