• Register
Welcome to the in5 Answer Exchange! This a place to get answers about in5 (InDesign to HTML5) and make requests.
0 votes
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?
in how_to by (290 points)
    

1 Answer

0 votes
 
Best answer

You can add an onerror attribute to your iframe, e.g.:

<iframe src="..." onerror="..."></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.

by (183k points)
selected by