Reputation: 5259
I have a very basic HTML5 page setup for offline use which tells me when it is offline and when it is online.
I've added location tracking to it to record the position of the device while it is running:
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(success, error);
} else {
alert('geolocation not supported');
}
setTimeout(function() { getLocation(); },5000); // calls itself every 5 seconds
}
This seems to work well, however there is a small problem.
On a desktop browser, you can minimize the page and the location keeps being recorded.
On a mobile device (i.e. iOS), when you minimize the browser, it is suspended i.e. the location no longer gets recorded.
Is there a way to force a webpage to be 'kept alive' on mobile devices? I know there's a similar feature for apps where you can go back to the homescreen and the app keeps running.
As you can see, this is not a "session being lost" issue, it is simply that all scripts on the page are stopped while the web page is not being viewed.
Upvotes: 1
Views: 3062
Reputation: 3
You can try to for loop an audio an file and play it and this will help the browser to run in the background forever.
Upvotes: 0
Reputation: 250972
You can't force a page to stay active - this is out of your control as the operating system suspends or tomb-stones the browser to save resources.
Upvotes: 2