In my book i use some source from web displaying in iframe. When device is offline there is empety space, with error message. Is any way to make some if statment js script to show notification in this place when device haven't got internet acces?
1 answer
Accepted answer
You can add an onerror attribute to your iframe, e.g.:
<iframe src="..."></iframe>
Here's a live example that uses two different methods using jQuery (which is included with in5 output):
https://jsfiddle.net/0z9mu8Lb/
I did some more testing and found the onerror event is only firing properly in Firefox.
These solutions offer a cross-browser method: https://jsfiddle.net/justinputney/jpaaytc4/2/
Essentially, it adds a navigator.onLine check inside the onload attribute of the iframe. If offline, the onerror attribute code is evaluated.