H5切换至后台页面
先说重点,试了很多种方法,这个真实有效
var reLoadLeftTime = false ;
//监听浏览器当前页面是否被激活的事件
var hiddenProperty = 'hidden' in document ? 'hidden' : 'webkitHidden' in document ? 'webkitHidden' : 'mozHidden' in document ? 'mozHidden' : null;
var visibilityChangeEvent = hiddenProperty.replace(/hidden/i, 'visibilitychange');
var onVisibilityChange = function()
{
if(!document[hiddenProperty]){
reLoadLeftTime = true;
// currentPeriod();
}
}
document.addEventListener(visibilityChangeEvent, onVisibilityChange);
原文:https://blog.csdn.net/qq_31940095/article/details/78562160 (感谢作者)