The EventSource interface is used to receive server-sent events. It connects to a server over HTTP and receives events in text/event-stream format without closing the connection.
PropertiesEdit
This interface also inherits properties from its parent, EventTarget.
EventSource.onerror- Is an
EventHandlerbeing called when an error occurs and theerrorevent is dispatched on this object. EventSource.onmessage- Is an
EventHandlerbeing called when amessageevent is received, that is when a message is coming from the source. EventSource.onopen- Is an
EventHandlerbeing called when anopenevent is received, that is when the connection was just opened. EventSource.readyStateRead only- An
unsigned shortrepresenting the state of the connection. Possible values areCONNECTING(0),OPEN(1), orCLOSED(2). EventSource.urlRead only- A
DOMStringrepresenting the URL of the source.
MethodsEdit
This interface also inherits methods from its parent, EventTarget.
EventSource.close()- Closes the connection, if any, and sets the
readyStateattribute toCLOSED. If the connection is already closed, the method does nothing.
SpecificationsEdit
| Specification | Status | Comment |
|---|---|---|
| WHATWG HTML Living Standard The definition of 'EventSource' in that specification. |
Living Standard |