<img onerror="myFunction()"> - Javascript DOM Event

Javascript examples for DOM Event:onerror

Description

The onerror event is triggered if an error occurs while loading an external document or image.

Summary

Bubbles No
Cancelable No
Supported HTML tags: <img>, <input type="image">, <object>, <link>, and <script> <audio> and <video>

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<img src="http://java2s.com/resources/a.png" onerror="myFunction()">

<p id="demo"></p>

<script>
function myFunction() {//from  w w w  . j ava  2s  . c o  m
    document.getElementById("demo").innerHTML = "The image could not be loaded.";
}
</script>

</body>
</html>

Related Tutorials