当我锁定iPhone时Javascript停止,它还可以运行吗? [英] Javascript stops as I lock iphone, can it still run?

查看:140
本文介绍了当我锁定iPhone时Javascript停止,它还可以运行吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法告诉javascript函数即使手机被锁定也能继续运行?

Is there a way to tell a javascript function to continue running even as a phone is locked?

我有一个计时器,我需要继续运行即使手机设置为空闲。

Pretty much I have a timer that I need to continue to run even as the phone is set to idle.

推荐答案

是的,你可以。当safari在后台时,您甚至可以运行JavaScript。

Yes, you can. You can even run a JavaScript when the safari is in the background.

只需在您的网站上放置一个隐藏的框架:

Just put a hidden frame on your site:

<iframe src="background.html" style="display:none;"></iframe>

background.html:

background.html:

<!DOCTYPE HTML>
<head>
<meta http-equiv="refresh" content="3" />
</head>
<body>
<script>
parent.run_function_from_core_page();
</script>
</body>
</html>

隐藏帧中的页面每3秒刷新一次,并运行JavaScript,即使手机是已锁定。

The page in the hidden frame refreshes every 3 seconds, and run the JavaScript, even if the phone is locked.

请注意,如果您不使用WiFi,也会导致高数据流量!

Be careful because it can lead to high data traffic also if you are not on WiFi!

这篇关于当我锁定iPhone时Javascript停止,它还可以运行吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆