baker icon indicating copy to clipboard operation
baker copied to clipboard

Using external content and testing for internet access

Open joshbaltzell opened this issue 14 years ago • 7 comments

I'd like to redirect my users to a signup form that renders either within Baker or directly in Safari, but I'd like to gracefully handle situations where they do not have internet access. Is there a way for me to test and show one page if they have internet access and one if they don't? Maybe a JS trick?

joshbaltzell avatar Dec 16 '11 15:12 joshbaltzell

Yup, you should be able to load a page (the one that will be displayed if online) and then modify it when it finds a connection. :)

folletto avatar Dec 16 '11 15:12 folletto

yes , but how?

mutador avatar Dec 29 '11 10:12 mutador

The outline of what the script should do is:

  1. You try to connect to the server using JS and XMLHTTPRequest
  2. If it can't connect, then you are offline.
  3. If it can connect, you download the HTML/JSON/XML/anything and update the localstorage data store.
  4. You then display the latest content from either the book or the localstorage data store.

Done. :)

folletto avatar Dec 29 '11 12:12 folletto

Did anyone write successfully this javascript code in the end? :)

folletto avatar Feb 14 '12 00:02 folletto

If you're using jQuery this is easy:

$.ajax({ url: "http://servicetoconnectto.com/", datatype: "xml", success: function(xml){ //actions on successful connect go here... update localstorage? }, error: function(jqXHR, exception) { //Display a message or do nothing - we're unable to connect for whatever reason. Probably offline but server could be down. } });

davidrsim avatar Apr 16 '12 13:04 davidrsim

can we load installed app?

rahuxx avatar Apr 21 '12 12:04 rahuxx

Could you please clarify? :)

folletto avatar Apr 21 '12 12:04 folletto