参考NoSleep.js
Prevent display sleep and enable wake lock in all Android and iOS web browsers.
Create a new NoSleep object and then enable or disable it when needed as follows:
var noSleep = new NoSleep();
function enableNoSleep() {
noSleep.enable();
document.removeEventListener('click', enableNoSleep, false);
}
// Enable wake lock.
// (must be wrapped in a user input event handler e.g. a mouse or touch handler)
document.addEventListener('click', enableNoSleep, false);
// ...
// Disable wake lock at some point in the future.
// (does not need to be wrapped in any user input event handler)
noSleep.disable();
1.在PC上的CHROME上enable后,会导致间隔几秒就刷新一次网页,其它浏览器未遇到。手机上经验证,也不会自己刷新。所以可以判断一下H5是不是在手机上运行,再去enable
2.注意必须是HTML元素触发的原生事件中,调用enable才会生效。