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 −


Live Demo

<!DOCTYPE html>

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

         function display() {
            alert("Image load unsuccessful.");
Published on 14-Mar-2018 09:50:17