View video tutorial

HTML onabort Attribute

HTML

The HTML onabort attribute defines a script that will be executed when the loading of a media file (such as an image, audio, or video) is canceled, stopped, interrupted, or aborted by the user or browser, not due to a loading error.

Definition and Usage


➔ The abort event occurs when the user or browser cancels loading.

➔ If the loading is aborted due to some other error, the abort event is not triggered. The corresponding error event will be triggered.

Example
    <section>
        <video id="myVideo1" src="" controls onclick="alert('Video loading aborted')"></video>
    </section>

➔ If you need to use the onabort event, use onabort instead of onclick.

Example
<!DOCTYPE html>
<html>
<head>
    <title>HTML onabort attribute example</title>
    <meta charset="utf-8" />
</head>
<body>
    <h2>HTML onabort attribute example</h2>
    <section>
        <video id="myVideo2" src="" controls="controls" onclick="handlerFunction()">
            <source src="video-path" type="video_type">
        </video>
    </section>
    <script>
        function handlerFunction() {
            alert("Video loading aborted.");
        }
    </script>
</body>
</html>
<!-- If you need to use the onabort event, use onabort instead of onclick.  -->

Applies to

This attribute can be used on the following element.

Attribute Element
onabort <audio>, <embed>, <img>, <object>, <video>