Home > Web Front-end > H5 Tutorial > 在移动端上,JS如何能知道浏览器已经被切换到后台了?

在移动端上,JS如何能知道浏览器已经被切换到后台了?

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-07 08:43:27
Original
3547 people have browsed it

回复内容:

iOS 上利用后端 JS 不执行的特性,加一个心跳机制,判断超时即在后台
<code class="language-text">var lastFired = new Date().getTime();
setInterval(function() {
    now = new Date().getTime();
    if(now - lastFired > 5000) { // if it's been more than 5 seconds
        alert("onfocus");
    }
    lastFired = now;
}, 500);
</code>
Copy after login
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template