Reputation: 1374
I use a service worker pattern that returns an offline.html if the in case that the network disconnects.
It works well: the program loads the intial page my_site.html.
Through out the program, the network disconnects, the service worker detects this and loads the offline.html page:
When the service worker returns the offline.html page, the Javascript uses window.location.href = response.url;
which reloads the page and changes the address bar to offline.html.
But then, how does the user recover the original html page, once the network re-connects?
Naturally, the user will refresh/reload the page. But this operation will keep asking for the last address (offline.html)
But the user expects to see the original page: my_site.html ?
Thanks,
Avner
Upvotes: 0
Views: 42
Reputation: 1374
The solution is to replace the page content without using window.location.href = ...
which forces to reload the page and change the address bar.
See here
Upvotes: 0
Reputation: 387
The navigator.onLine
property provides a boolean value if a user is online.
if (navigator.onLine) { // true / false
// redirect user
}
Upvotes: 1