Skip to content
Related Articles

Related Articles

HTML | DOM onopen Event

Improve Article
Save Article
  • Last Updated : 30 Jul, 2019
Improve Article
Save Article

The DOM onopen event occurs on an open connection with an event source.

Related events:

  • onmessage: Received the message.
  • onerror: The problem occurs.


  • Using JavaScript:
    object.onopen = function(){myScript};
  • Using the addEventListener() method:
    object.addEventListener("open", myScript); 

Example: Using the addEventListener() method

<!DOCTYPE html>
        HTML DOM onopen Event
    <h1 id="gfg"></h1>
    <div id="geeks"></div>
        if (typeof(EventSource) !== "undefined") {
            var source = new EventSource("/html/demo_sse.php");
            source.addEventListener("open", function() {
                document.getElementById("gfg").innerHTML = 
            source.addEventListener("message", function(event) {
                document.getElementById("geeks").innerHTML +=
         + "<br>";
        } else {
            document.getElementById("gfg").innerHTML = 
              "Browser does not support";


Supported Browsers: The browsers supported by HTML DOM onopen Event are listed below:

  • Google Chrome 9.0
  • Firefox 6.0
  • Apple Safari 5.0
  • Opera 11.0

My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!