Execute a script when an error occurs in HTML?

HTMLWeb DevelopmentFront End Technology

The onerror event triggers when an error occurs in HTML. You can try to run the following code to implement onerror event attribute −

Example

Live Demo

<!DOCTYPE html>
<html>
   <body>

      <img src = "new.png" onerror = "display()">
      <p>Alert would be visible, if the image isn't loaded correctly.</p>

      <script>
         function display() {
            alert("Image load unsuccessful.");
         }
      </script>
   </body>
   
</html>
raja
Published on 14-Mar-2018 14:20:17
Advertisements