我正在实现一个javascript计时器,该计时器会在iframe中加载,并且该计时器也会以一定的时间间隔播放一些音频文件,基本上它用于例行演习,因此说10秒钟有第一个练习,然后第二个1分钟,第二个1分钟,等等。使用javascript阻止Safari进入睡眠状态
随着锻炼时间的完成和下一个锻炼时间的增加,我改变了特定练习的音频等等。我想要的是防止浏览器在手机(android,iOS),笔记本电脑等各种模式下休眠,直到定时器运行时为止。
我已经使用了2个ios解决方案我正在使用重新加载页面和其他人是否是Android或笔记本电脑我正在尝试视频here。
而我最终的代码来检查的事情是
var ua = {
Android: /Android/ig.test(navigator.userAgent),
// iOS: /AppleWebKit/.test(navigator.userAgent) && /Mobile\/\w+/.test(navigator.userAgent)
iOS:/iPhone|iPad|iPod/i.test(navigator.userAgent)
};
<script type="text/javascript" src="js/sleep.js"></script>
if (ua.iOS) {
preventIosSleep = setInterval(function(){
window.top.location.href = '/';
setTimeout(function(){
try {
window.top.stop();
} catch (exception) {
document.execCommand('Stop');
}
}, 0);
}, 10000);
} else {
sleep.prevent();
}
// and when releasing the things
if (ua.iOS) {
clearInterval(preventIosSleep);
} else {
sleep.allow();
}
的sleep.js从连杆作为上述告知。现在一直在尝试大约一周的时间。除了MAC上的Safari浏览器之外,此解决方案适用于所有浏览器。任何人都可以告诉我如何停止Safari浏览器不进入睡眠模式。
你不能........你是在浏览器的摆布。 –
你的“最终代码来检查事情”有'AppleWebKit' regex注释掉了,所以'ua.iOS'甚至不会在macOS上检测到Safari。你至少证实你可以在macOS上检测到Safari吗? –