visibilitychange event is not triggered when switching program/window with ALT+TAB or clicking in taskbar

前端 未结 4 436
谎友^
谎友^ 2020-12-02 23:15

The problem is with the behaviour of the event \"visibilitychange\".

It\'s triggered: - When I switch to a different tab inside the browser window.

4条回答
  •  孤城傲影
    2020-12-02 23:38

    There's a very simple solution to this I have come across.

    You just need to pass false to the useCapture while attaching an event listener to the document. Works like a charm!

     document.addEventListener('visibilitychange', function () {
      // code goes here
    }, false)
    

提交回复
热议问题