The DOM onopen event occurs on an open connection with an event source.
Related events:
- onmessage: Received the message.
- onerror: The problem occurs.
Syntax:
- Using JavaScript:
object.onopen = function(){myScript}; - Using the addEventListener() method:
object.addEventListener("open", myScript);
Example: Using the addEventListener() method
<!DOCTYPE html> <html> <head> <title> HTML DOM onopen Event </title> </head> <body> <h1 id="gfg"></h1> <div id="geeks"></div> <script> if (typeof(EventSource) !== "undefined") { var source = new EventSource("/html/demo_sse.php"); source.addEventListener("open", function() { document.getElementById("gfg").innerHTML = "GeeksforGeeks"; }); source.addEventListener("message", function(event) { document.getElementById("geeks").innerHTML += event.data + "<br>"; }); } else { document.getElementById("gfg").innerHTML = "Browser does not support"; } </script> </body> </html> |
chevron_right
filter_none
Output:

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
Recommended Posts:
- HTML | DOM fullscreenerror Event
- HTML | DOM onvolumechange Event
- HTML | DOM ondragleave Event
- HTML | DOM onpaste Event
- HTML | DOM touchcancel Event
- HTML | DOM touchmove Event
- HTML | DOM Storage Event
- HTML | DOM createEvent() Event Method
- HTML | DOM touchend Event
- HTML | DOM timeStamp Event Property
- HTML | DOM stopPropagation() Event Method
- HTML | DOM cancelable Event Property
- HTML | DOM type Event Property
- HTML | DOM touchstart Event
- HTML | DOM onpause Event
- HTML | DOM onabort Event
- HTML | DOM onsuspend Event
- HTML | DOM oninvalid Event
- HTML | DOM onfocus Event
- HTML | DOM ondrop Event
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


