onabort

The onabort event is triggered when the loading of an audio or video file is canceled. It happens when a download is stopped.

onabort event

The onabort event is triggered when the user cancels the loading of media (<audio> or <video>). This is different from the onerror event, which deals with errors during loading. To use it, attach onabort to a media element and define the JavaScript function to run when the event occurs.

Syntax

In HTML

index.html
<element onabort="myScript">

In JS

script.js
object.onabort = function(){myScript};

In JavaScript, the addEventListener() function is used.

script.js
object.addEventListener("abort", myScript);

Values

  • <script>
    • The function that should be executed when the event is triggered.

Conclusion

The onabort event is triggered when media loading (<audio> or <video>) is canceled by the user. It is different from the onerror event, which handles loading errors. By attaching onabort to a media element, you can define a JavaScript function to execute when the event occurs.