In JavaScript:
object.onerror = function(){
myScript};
<!DOCTYPE html> <html> <body> <p>This example uses the HTML DOM to assign an "onerror" event to an img element.</p> <img id="myImg" src="wrong.gif"> <p id="demo"></p> <script> document.getElementById("myImg").onerror = function() {myFunction()}; function myFunction() {/* w w w . j av a 2 s . c o m*/ document.getElementById("demo").innerHTML = "The image could not be loaded."; } </script> </body> </html>
Bubbles: | No |
---|---|
Cancelable: | No |
Event type: | UiEvent if generated from a user interface, Event otherwise |
Supported HTML tags: | <img>, <input type="image">, <object>, <link>, and <script> |