Revision 37528 of error

  • Revision slug: DOM/DOM_event_reference/error
  • Revision title: error
  • Revision id: 37528
  • Created:
  • Creator: Nickolay
  • Is current revision? No
  • Comment 1 words added, 1 words removed

Revision Content

Summary

The error event is fired whenever a resource fails to load.

Target(s) Event Type Bubbles Cancellable Specification[note] Notes
{{ domxref("HTMLElement") }} {{ domxref("Event") }} no? no? HTML5 (in many situations)

A resource failed to load. There are many specific circumstances when this event is fired, e.g. for the frame, iframe, img[note], link, script[note], style elements. See details in the HTML specification.

TODO: split specific cases into their own rows, as necessary.

{{ domxref("HTMLMediaElement") }} {{ domxref("Event") }} no no HTML5: Media elements — Event summary An error occurs while fetching the media data for an {{ HTMLElement("audio") }} or a {{ HTMLElement("video") }} element.
{{ domxref("XMLHttpRequest") }} {{ domxref("ProgressEvent") }} ? ? XMLHttpRequest Level 2  

The HTML specification also requires the event to fire for some non-Element objects, including workers, EventSource (server-sent events). (TODO: list them in the table above.)

Run-time script errors are reported (per the HTML specification) via {{ domxref("window.onerror") }} and the onerror attributes on {{ HTMLElement("body") }} and {{ HTMLElement("frameset") }}.

Notes

error with img elements

For {{ HTMLElement("img") }} elements, an error event is triggered in the following cases:

  • Network error (DNS error, for instance)
  • Incorrect Content-Type HTTP header (doesn't start with "image/")
  • Content-Length HTTP header is 0
  • HTTP response code is 204 (No content)

Even though this is not standardized, this behavior is consistent across web browsers.

Nokia phones (Symbian OS) running a WebKit browser do not fire any events when the Content-Length HTTP header is 0. In this case, no event is fired (neither error nor load).

error with script elements

Prior to Firefox 14, the error event script could bubble, and the string "Error loading script" could be passed instead of the Event object to the event handler (see {{ bug("737087") }}).

DOM Level 3 Events specification

The DOM Level 3 Events specification mentions the error event, but does not define the specific cases when the event should be fired. It is therefore not mentioned in the section above.

Revision Source

<h2>Summary</h2>
<p>The error event is fired whenever a resource fails to load.</p>
<table class="standard-table" style="width: auto;"> <thead> <tr> <th scope="col">Target(s)</th> <th scope="col">Event Type</th> <th scope="col">Bubbles</th> <th scope="col">Cancellable</th> <th scope="col">Specification<sup><a href="#note-DOM-L3-Events">[note]</a></sup></th> <th scope="col">Notes</th> </tr> </thead> <tbody> <tr> <td>{{ domxref("HTMLElement") }}</td> <td>{{ domxref("Event") }}</td> <td>no?</td> <td>no?</td> <td><a class="external" href="http://www.whatwg.org/specs/web-apps/current-work/">HTML5</a> (in many situations)</td> <td> <p>A resource failed to load. There are many specific circumstances when this event is fired, e.g. for the frame, iframe, img<sup><a href="#note-img">[note]</a></sup>, link, script<sup><a href="#note-script">[note]</a></sup>, style elements. See details in the HTML specification.</p> <p>TODO: split specific cases into their own rows, as necessary.</p> </td> </tr> <tr> <td>{{ domxref("HTMLMediaElement") }}</td> <td>{{ domxref("Event") }}</td> <td>no</td> <td>no</td> <td><a class="external" href="http://www.whatwg.org/specs/web-apps/current-work/multipage/the-video-element.html#event-media-error">HTML5: Media elements — Event summary</a></td> <td>An error occurs while fetching the media data for an {{ HTMLElement("audio") }} or a {{ HTMLElement("video") }} element.</td> </tr> <tr> <td>{{ domxref("XMLHttpRequest") }}</td> <td>{{ domxref("ProgressEvent") }}</td> <td>?</td> <td>?</td> <td><a class="external" href="http://www.w3.org/TR/XMLHttpRequest/#event-xhr-error">XMLHttpRequest Level 2</a></td> <td> </td> </tr> </tbody>
</table>
<p>The HTML specification also requires the event to fire for some non-Element objects, including workers, EventSource (server-sent events). (TODO: list them in the table above.)</p>
<p>Run-time script errors are reported (per the <a class="external" href="http://www.whatwg.org/specs/web-apps/current-work/multipage/webappapis.html#report-the-error">HTML specification</a>) via {{ domxref("window.onerror") }} and the <code>onerror</code> attributes on {{ HTMLElement("body") }} and {{ HTMLElement("frameset") }}.</p>
<h2>Notes</h2>
<h3 id="note-img"><code>error</code> with <code>img</code> elements</h3>
<p>For {{ HTMLElement("img") }} elements, an error event is triggered in the following cases:</p>
<ul> <li>Network error (DNS error, for instance)</li> <li>Incorrect <code>Content-Type</code> HTTP header (doesn't start with "image/")</li> <li><code>Content-Length</code> HTTP header is 0</li> <li>HTTP response code is 204 (No content)</li>
</ul>
<p>Even though this is not standardized, this behavior is consistent across web browsers.</p>
<p>Nokia phones (Symbian OS) running a WebKit browser do not fire any events when the <code>Content-Length</code> HTTP header is 0. In this case, no event is fired (neither <code>error</code> nor <code>load</code>).</p>
<h3 id="note-script"><code>error</code> with <code>script</code> elements</h3>
<p>Prior to Firefox 14, the <code>error</code> event script could bubble, and the string "Error loading script" could be passed instead of the <code>Event</code> object to the event handler (see {{ bug("737087") }}).</p><h3 id="note-DOM-L3-Events">DOM Level 3 Events specification</h3>
<p>The <a class="external" href="http://www.w3.org/TR/DOM-Level-3-Events/#event-type-error">DOM Level 3 Events</a> specification mentions the <code>error</code> event, but does not define the specific cases when the event should be fired. It is therefore not mentioned in the section above.</p>
Revert to this revision