Detect when a browser page window loses focus with Alt-Tab using pure JS or jQuery

后端 未结 2 1775
孤独总比滥情好
孤独总比滥情好 2020-12-21 00:07

Is it possible to detect current page is in alt-tab? This code works only if a new tab in browser is opened:

(function() {
  var hidden = \"hidden\";

  // S         


        
2条回答
  •  星月不相逢
    2020-12-21 01:06

    There is a Page Visibility API available: https://developer.mozilla.org/en-US/docs/Web/API/Page_Visibility_API

    document.addEventListener("visibilitychange", handleVisibilityChange, false)
    

提交回复
热议问题