In JavaScript, using the addEventListener()
method:
object.addEventListener("error",
myScript);
This example uses the addEventListener()
method to attach a "error" event to an img element.
<!DOCTYPE html> <html> <body> <img id="myImg" src="wrong.gif"> <p id="demo"></p> <script> document.getElementById("myImg").addEventListener("error", myFunction); function myFunction() {//from www.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> |