mozilla

Revision 37525 of error

  • Revision slug: DOM/DOM_event_reference/error
  • Revision title: error
  • Revision id: 37525
  • Created:
  • Creator: Nickolay
  • Is current revision? No
  • Comment This page attempted to document multiple distinct cases at once. Make this clearer and make a (incomplete) table of cases to be documented. Also mention more cases where the event is fired.; 231 words added, 16 words removed

Revision Content

Summary

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

Target(s) Event Type Bubbles Cancellable Specification 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, link, script, 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

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).

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</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, link, script, 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>
<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>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