In a web viewer or web overlay, you can refer to a remote url or to a local WebResource, depending on whether a user is online or not.
The sample file contains a publication with 3 different articles:
- The first article shows a web viewer containing a link to a remote website.
- The second article shows a local WebResource which is embedded in the publication
- The third article is a smart article. It will check if the device is online, and if it is, it will show a link to a remote web site. If the device is offline, it will show a local WebResource which is embedded in the publication.
The way we’ve implemented it in the third article is by adding an extra file called
check.html in the WebResources folder for the publication. In that file, we’ve pasted the following HTML code:
Whenever the page gets loaded, it will execute the script. With the call to
navigator.onLine (case-sensitive), it will ask the web browser if there is an internet connection. If there is an internet connection, it will redirect to the HTTP url, if not, it will show the local WebResource. If you preview the sample publication on your device, load it first with a network connection. On the third article, it will tell you that an online page was loaded. If you then e.g. turn on Airplane mode in the system settings and open the publication again, the third article will automatically load the offline file. This technique is very handy if you have certain content that is only available online. Using this check, you can show a proper message to the user indicating that he/she needs to be online to view that content.