Using external content and testing for internet access
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?
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. :)
yes , but how?
The outline of what the script should do is:
- You try to connect to the server using JS and XMLHTTPRequest
- If it can't connect, then you are offline.
- If it can connect, you download the HTML/JSON/XML/anything and update the localstorage data store.
- You then display the latest content from either the book or the localstorage data store.
Done. :)
Did anyone write successfully this javascript code in the end? :)
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. } });
can we load installed app?
Could you please clarify? :)