onerror Event
Example
If there is a problem with the event stream, perform the following operations:
var source = new EventSource("demo_sse.php"); source.onerror = function() { // Code to handle errors };
Definition and Usage
An onerror event occurs when an error occurs in the event source.
An error usually occurs when the connection is interrupted. If this happens, the EventSource object will automatically try to reconnect to the server.
Related events:
- onmessage - Occurs when a message is received
- onopen - Occurs when the connection to the server is opened
For more information on server-sent events, please read our HTML5 Server-Sent Events Tutorial.
Browser Support
Event | Chrome | IE | Firefox | Safari | Opera |
---|---|---|---|---|---|
onerror | 9.0 | Not Supported | 6.0 | 5.0 | 11.0 |
Syntax
object.onerror = function(){myScript};
Use the addEventListener() method:
object.addEventListener("error", myScript);
Note:Internet Explorer 8 or earlier versions do not support addEventListener() Method.
Technical Details
Bubbling: | Not Supported |
---|---|
Cancelable: | Not Supported |
Event Type: | Event |