VOOZH about

URL: https://www.geeksforgeeks.org/html/html-dom-onmessage-event/

⇱ HTML | DOM onmessage Event - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

HTML | DOM onmessage Event

Last Updated : 16 Aug, 2022

The onmessage Event in HTML DOM used when an object has received some message through an event source. The event object for onmessage Event supports the following schemes:

  • data: It contains the actual message present inside it.
  • origin: It contains the URL of the document that invoked the event.
  • lastEventId: It works as descriptive attribute for the last message that was spotted in the message stream.

Note: Server-Sent Events are not supported in Internet Explorer. 

Syntax:

object.onmessage = function(){myScript}; 
  • Using the addEventListener() method
object.addEventListener("message", myScript);

Example 1: 

Output:

 👁 Image
 

Example 2: Using the addEventListener() method 

Output:

 👁 Image
 

Supported browsers: The browser supported by onmessage Event are listed below:

  • Google Chrome 60.0
  • Edge 12.0
  • Mozilla Firefox 9.0
  • Internet Explorer 8.0
  • Apple Safari 4.0
  • Opera 47.0
Comment
Article Tags: