--- title: HTMLMediaElement.onerror slug: Web/API/HTMLMediaElement/onerror translation_of: Web/API/HTMLMediaElement/onerror ---
{{APIRef("HTML DOM")}}

The onerror property of the {{domxref("HTMLMediaElement")}} interface is the {{event("Event_handlers", "event handler")}} for processing {{event("error")}} events.

The error event fires when some form of error occurs while attempting to load or perform the media.

语法

HTMLMediaElement.onerror = EventListener;

Value

A {{jsxref("function")}} which serves as the event handler for the {{event("error")}} event. When an error occurs, the specified function will be called. If null, no error handler is in effect.

Specifications

Specification Status Comment
{{SpecName('HTML WHATWG','webappapis.html#handler-onerror','onerror')}} {{Spec2('HTML WHATWG')}}

Browser compatibility

{{Compat("api.HTMLMediaElement.onerror")}}

See also