onopen Event
Definition and Usage
The onopen event occurs when the connection with the event source is opened.
Related Events:
For more knowledge about server-sent events, please learn our HTML5 Server-Sent Events Tutorial.
Example
Create a new EventSource object and specify the URL of the page that sends updates.
When (and if) a connection is established, output some text in the <h1> element:
var source = new EventSource("demo_sse.php"); source.onopen = function() { document.getElementById("myH1").innerHTML = "Getting server updates"; };
Syntax
object.onopen = function(){myScript};
Using addEventListener() Method:
object.addEventListener("open", myScript);
Note:Internet Explorer 8 and earlier versions do not support addEventListener() Method.
Technical Details
Bubbling: | Not Supported |
---|---|
Cancellable: | Not Supported |
Event Type: | Event |
Browser Support
The numbers in the table indicate the first browser version that fully supports the event.
Events | Chrome | IE | Firefox | Safari | Opera |
---|---|---|---|---|---|
onopen | 9.0 | Not Supported | 6.0 | 5.0 | 11.0 |