THE WORLD'S LARGEST WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

onopen Event

Event Object Reference Event Object

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 »

Definition and Usage

The onopen event occurs when a connection with an event source is opened.

Related events:

  • onmessage - Occurs when a message is received
  • onerror - Occurs when a problem occurs

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 »

Note: The addEventListener() method is not supported in Internet Explorer 8 and earlier versions.


Technical Details

Bubbles: No
Cancelable: No
Event type: Event

Event Object Reference Event Object