onopen Event
Example
Create a new EventSource object, and specify the URL of the page sending the
updates.
When (and if) a connection is established, output some text in a
<h1> element:
var source = new EventSource("demo_sse.php");
source.onopen = function() {
document.getElementById("myH1").innerHTML = "Getting server updates";
};
Try it Yourself »
Description
The onopen event occurs when a connection with an event source is opened.
Related events:
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 | |||||
---|---|---|---|---|---|
onopen | 9.0 | Not supported | 6.0 | 5.0 | 11.0 |
Syntax
object.onopen = function(){myScript};
Try it Yourself »
Using the addEventListener() method:
object.addEventListener("open", myScript);
Try it Yourself »
Technical Details
Bubbles: | No |
---|---|
Cancelable: | No |
Event type: | Event |
Copyright 1999-2023 by Refsnes Data. All Rights Reserved.