javascript - How to tell if the user has switched to the current tab?
三叔
三叔 2017-07-05 10:38:13
0
2
812

I noticed that YouTube will only start playing the video when the user switches to the current tab.
So when a user opens multiple tabs, how to determine whether the user has switched to the current tab?

三叔
三叔

reply all(2)
小葫芦

There is a Page Visibility API, you can take a look

I have thought about this implementation before, but it actually has shortcomings. What if sometimes I just want to listen to the sound? (:evil

Peter_Zhu
document.addEventListener('visibilitychange', function() {
    if (!document.hidden) {
        // code
    }
})
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!