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.html");
source.onopen = function() {
document.getElementById("myH1").innerHTML = "Getting server updates";
};
Try it Yourself »
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.
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 |
object.onopen = function(){
myScript};
Try it Yourself »
Using the addEventListener() method:
object.addEventListener("open",
myScript);
Try it Yourself »
Bubbles: | No |
---|---|
Cancelable: | No |
Event type: | Event |
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!