Event for browser tab hidden/shown?

前端 未结 3 749
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-06 08:26

Is there any DOM event for when the browser tab loses/gains focus? I know there are the blur and focus events on window, but they also

相关标签:
3条回答
  • 2021-01-06 09:06

    The closest thing I believe you'll find is the top answer here:

    Is there a way track the focus on tab with Javascript?

    0 讨论(0)
  • 2021-01-06 09:16

    At least Google Chrome supports a webkitvisibilitychange event and a document.webkitHidden property. See the visibility API. But it seems only to fire when the shown tab changes, not when the whole window is minimized. There also seems to be a visibilitychange event for Internet Explorer, but the documentation doesn't say anything about it.

    0 讨论(0)
  • 2021-01-06 09:23

    Now they have exactly what was needed: https://developer.mozilla.org/en-US/docs/Web/Guide/User_experience/Using_the_Page_Visibility_API

    0 讨论(0)
提交回复
热议问题