THE WORLD'S LARGEST WEB DEVELOPER SITE

onerror Event

❮ Event Object

Example

Do something if a problem occurs with the event stream:

var source = new EventSource("demo_sse.php");
source.onerror = function() {
    // Do something to handle error
};


Definition and Usage

The onerror event occurs when an error occurs with the event source.

An error usually occurs when a connection is disrupted. If this happens, the EventSource object will automatically attempt to reconnect to the server.

Related events:

  • onmessage - Occurs when a message is received
  • onopen - Occurs when a connection to the server is open

For more information about Server-Sent Events, read our HTML5 Server-Sent Events Tutorial.


Browser Support

The numbers in the table specify the first browser version that fully supports the event.

Event
onerror 9.0 Not supported 6.0 5.0 11.0

Syntax

object.onerror = function(){myScript};

Using the addEventListener() method:

object.addEventListener("error", myScript);

Note: The addEventListener() method is not supported in Internet Explorer 8 and earlier versions.


Technical Details

Bubbles: No
Cancelable: No
Event type: Event

❮ Event Object