3

I'm trying to use jquery to detect whether an iframe fails to load or the page doesn't exist, but the code below isn't working:

$('#frame').error(function(){
    //code here
});
Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055
Kevin Pei
  • 5,800
  • 7
  • 38
  • 55

2 Answers2

2

One of the comments on the documentation says:

Using .error() on an iframe never seems to trigger (even though .load() will trigger on a successful iframe load).

This event does not appear to be designed to work in this use case.

The answers to this question explain how to do it.

Community
  • 1
  • 1
Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055
0

iframe do not trigger onerror event even if it fails to load the document. I think load will be triggered even in this case and you can check for the status code to determine if the page is loaded successfully or no.

ShankarSangoli
  • 69,612
  • 13
  • 93
  • 124