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.
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:
<!DOCTYPE HTML>
<head>
<meta http-equiv="refresh" content="3" />
</head>
<body>
<script>
parent.run_function_from_core_page();
</script>
</body>
</html>
The page in the hidden frame refreshes every 3 seconds, and run the JavaScript, even if the phone is locked.
Be careful because it can lead to high data traffic also if you are not on WiFi!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With