williamsandonz
williamsandonz

Reputation: 16420

iPhone HTML5 website on homescreen with jQuerymobile offline splash page?

How do I go about loading a splash to the user if they are offline? I want it to show after the initial loading image, I have a page called gone-offline.jsp but how to detect if user is offline on mobileinit?

I'm not using phone-gap

Upvotes: 0

Views: 339

Answers (2)

Joeri Minnekeer
Joeri Minnekeer

Reputation: 602

it's very simple using javascript.

if(navigator.onLine)
{
 //online code here
}else{
 //offline code here
}

(done with jQ mobile)

Upvotes: 0

Dessus
Dessus

Reputation: 2177

You need to decide what offline means to your business scnenario. This may sounds silly, but it depends on what your app wants to do. For example:

Does your app want to go offline when it is actually offline and can't reach other websites, or does it want be in offline status when it can't access your webservice.

Assuming you want to test that there is no connection to your webservice I would recommend the following:

1) Make an ajax call every x number of minutes to your webservice to check if it is still online 2) make a common method that handles time outs if your application thinks its online and is offline. 3) make it so that when your application is offline, it is trying to get back online in the background by doing a similar step to step 1.

To do ajax with JQuery see: http://api.jquery.com/jQuery.ajax/

Note that if you require cross domain json (you may or may not) then you will need to investigate CORS/JSON-P/XSS with iframes.

Upvotes: 1

Related Questions