Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Checking online status from an iPhone web app

Is there a way to check to see if an iPhone is online from a web app. That is, in mobile Safari, can I check the online status of the device to see if I should try an AJAX call or not.

In Firefox/regular WebKit, this would be:

if(navigator.onLine) 
{
    onlineCode() 
}
like image 589
Ted Avatar asked Sep 15 '08 20:09

Ted


3 Answers

img src="http://aonlinesite.com/a-really-little-image.png" onload="Intenet!" onerror="NoInternet!"

like image 102
Isaac Waller Avatar answered Oct 06 '22 17:10

Isaac Waller


A quick test on the iPhone shows that it is available from iPhone OS 2.2.

like image 3
pr1001 Avatar answered Oct 06 '22 18:10

pr1001


That same code should work in the WebKit nightly build as of May 16th 2008. I guess that means you need to hope the 2.1 update included a new build of safari.

https://bugs.webkit.org/show_bug.cgi?id=19105

like image 2
Loren Segal Avatar answered Oct 06 '22 16:10

Loren Segal