SlideShare a Scribd company logo
Web Messaging
Web messaging is the ability to send real time messages from the server to the
client browser. It overrides the cross domain communication problem in different
domains, protocols or ports
For example, you want to send the data from your page to ad container which is
placed at iframe or voice-versa, in this scenario, Browser throws a security
exception. With web messaging we can pass the data across as a message event.
Message Event
Message events fires Cross-document messaging, channel messaging, server-
sent events and web sockets.it has described by Message Event interface.
Sr.No Attributes and Description
1 data
Contains string data
2 origin
Contains Domain name and port
3 lastEventId
Contains unique identifier for the current message event
4 source
Contains to A reference to the originating document's window
5 ports
Contains the data which is sent by any message port
Attributes
Sending a cross-document message
Before send cross document message, we need to create a new web browsing
context either by creating new iframe or new window. We can send the data
using with postMessage() and it has two arguments. They are as
 message - The message to send
 targetOrigin - Origin name
Examples
Sending message from iframe to button
var iframe document . querySe1ector( I iframe ' ) ; var button
document . querySe1ector( I button ' ) ;
var clickHand1er function() { iframe.contentWindow. postMessage(
'The message to send. ' ' https : / /www.texamine . com) ;
button . addEventListener( ' click , clickHand1er, false) ;
Receiving a cross-document message in the receiving document
var messageEventHand1er function (event) {
// check that the origin is one we want.
if (event . origin I https://www.texamine.com l ) { alert (event . data)
window. addEventListener( message ' messageEventHand1er, false)
Channel messaging
Two-way communication between the browsing contexts is called channel
messaging. It is useful for communication across multiple origins.
The MessageChanneI and MessagePort Objects
While creating messageChannel, it internally creates two ports to sending the
data and forwarded to another browsing context.
 postMessage() - Post the message throw channel
 start() - It sends the data
 close() - It close the ports
In this scenario, we are sending the data from one iframe to another iframe. Here
we are invoking the data in function and passing the data to DOM.
var loadHand1er function() { var mc, portMessageHand1er; mc new
MessageChanne1(); window. parent . postMessage( '
documentAHasLoaded ' , ' http://foo.example' , [mc . port 2] ) ;
portMessageHand1er function(portMsgEvent) {
alert( portMsgEvent.data ) ;
mc . portl. addEventListener( I message' ,
portMessageHand1er, false) mc . portl. start();
window. addEventListener( ' DOMContentLoaded ' , loadHand1er, false)
Above code, it is taking the data from port 2, now it will pass the data to second
iframe
var loadHand1er function() { var i frames,
messageHand1er; iframes = window. frames;
messageHand1erfunction(messageEvent) {
if( messageEvent.ports.1ength > e ) {
// transfer the port to iframe[l] iframes [1] . postMessage( ' portopen' , '
http://foo.example ' , messageEvent . ports) ;
window. addEventListener( ' message ' , messageHand1er, false) ;
window. addEventListener( ' DOMContentLoaded , loadHand1er, false) ;
Now second document handles the data by using the portMsgHandler function.
var loadHand1er() {
// Define our message handler function var messageHand1er
function(messageEvent) {
// Our form submission handler
var formHand1er function() { var msg ' add to game circle. '
messageEvent . ports [0] . postMessage(msg) ;
document . forms [0] . addEventListener( submit I , formHand1er, false) ;
window. addEventListener( ' message ' , messageHand1er, false) ;
window. addEventListener( ' DOMContentLoaded , loadHand1er, false) ;

More Related Content

Similar to Html web messaging

Message in a Bottle
Message in a BottleMessage in a Bottle
Message in a Bottle
Zohar Arad
 
Id32
Id32Id32
Id32
sandhish
 
Windows 8 metro applications
Windows 8 metro applicationsWindows 8 metro applications
Windows 8 metro applications
Alex Golesh
 
JavaScript Security: Mastering Cross Domain Communications in complex JS appl...
JavaScript Security: Mastering Cross Domain Communications in complex JS appl...JavaScript Security: Mastering Cross Domain Communications in complex JS appl...
JavaScript Security: Mastering Cross Domain Communications in complex JS appl...
Thomas Witt
 
Pushing the Web: Interesting things to Know
Pushing the Web: Interesting things to KnowPushing the Web: Interesting things to Know
Pushing the Web: Interesting things to Know
n|u - The Open Security Community
 
Engaging users with live tiles and notifications
Engaging users with live tiles and notificationsEngaging users with live tiles and notifications
Engaging users with live tiles and notifications
Alex Golesh
 
Html5 websockets
Html5 websocketsHtml5 websockets
Html5 websockets
AbhishekMondal42
 
IPC mechanisms in windows
IPC mechanisms in windowsIPC mechanisms in windows
IPC mechanisms in windows
Vinoth Raj
 
Websockets talk at Rubyconf Uruguay 2010
Websockets talk at Rubyconf Uruguay 2010Websockets talk at Rubyconf Uruguay 2010
Websockets talk at Rubyconf Uruguay 2010
Ismael Celis
 
Sse
SseSse
AJAX Transport Layer
AJAX Transport LayerAJAX Transport Layer
AJAX Transport Layer
Siarhei Barysiuk
 
Time for Comet?
Time for Comet?Time for Comet?
Time for Comet?
Simon Willison
 
Socket Programming it-slideshares.blogspot.com
Socket  Programming it-slideshares.blogspot.comSocket  Programming it-slideshares.blogspot.com
Socket Programming it-slideshares.blogspot.com
phanleson
 
Building interactivity with websockets
Building interactivity with websocketsBuilding interactivity with websockets
Building interactivity with websockets
Wim Godden
 
Networking & Socket Programming In Java
Networking & Socket Programming In JavaNetworking & Socket Programming In Java
Networking & Socket Programming In Java
Ankur Agrawal
 
Training cards implementation
Training cards implementationTraining cards implementation
Training cards implementation
Michael Aubrey Amann
 
16 18
16 1816 18
13 networking, mobile services, and authentication
13   networking, mobile services, and authentication13   networking, mobile services, and authentication
13 networking, mobile services, and authentication
WindowsPhoneRocks
 
Jsr120 sup
Jsr120 supJsr120 sup
Jsr120 sup
SMIJava
 
4Developers 2018: Real-time capabilities in ASP.NET Core web applications (To...
4Developers 2018: Real-time capabilities in ASP.NET Core web applications (To...4Developers 2018: Real-time capabilities in ASP.NET Core web applications (To...
4Developers 2018: Real-time capabilities in ASP.NET Core web applications (To...
PROIDEA
 

Similar to Html web messaging (20)

Message in a Bottle
Message in a BottleMessage in a Bottle
Message in a Bottle
 
Id32
Id32Id32
Id32
 
Windows 8 metro applications
Windows 8 metro applicationsWindows 8 metro applications
Windows 8 metro applications
 
JavaScript Security: Mastering Cross Domain Communications in complex JS appl...
JavaScript Security: Mastering Cross Domain Communications in complex JS appl...JavaScript Security: Mastering Cross Domain Communications in complex JS appl...
JavaScript Security: Mastering Cross Domain Communications in complex JS appl...
 
Pushing the Web: Interesting things to Know
Pushing the Web: Interesting things to KnowPushing the Web: Interesting things to Know
Pushing the Web: Interesting things to Know
 
Engaging users with live tiles and notifications
Engaging users with live tiles and notificationsEngaging users with live tiles and notifications
Engaging users with live tiles and notifications
 
Html5 websockets
Html5 websocketsHtml5 websockets
Html5 websockets
 
IPC mechanisms in windows
IPC mechanisms in windowsIPC mechanisms in windows
IPC mechanisms in windows
 
Websockets talk at Rubyconf Uruguay 2010
Websockets talk at Rubyconf Uruguay 2010Websockets talk at Rubyconf Uruguay 2010
Websockets talk at Rubyconf Uruguay 2010
 
Sse
SseSse
Sse
 
AJAX Transport Layer
AJAX Transport LayerAJAX Transport Layer
AJAX Transport Layer
 
Time for Comet?
Time for Comet?Time for Comet?
Time for Comet?
 
Socket Programming it-slideshares.blogspot.com
Socket  Programming it-slideshares.blogspot.comSocket  Programming it-slideshares.blogspot.com
Socket Programming it-slideshares.blogspot.com
 
Building interactivity with websockets
Building interactivity with websocketsBuilding interactivity with websockets
Building interactivity with websockets
 
Networking & Socket Programming In Java
Networking & Socket Programming In JavaNetworking & Socket Programming In Java
Networking & Socket Programming In Java
 
Training cards implementation
Training cards implementationTraining cards implementation
Training cards implementation
 
16 18
16 1816 18
16 18
 
13 networking, mobile services, and authentication
13   networking, mobile services, and authentication13   networking, mobile services, and authentication
13 networking, mobile services, and authentication
 
Jsr120 sup
Jsr120 supJsr120 sup
Jsr120 sup
 
4Developers 2018: Real-time capabilities in ASP.NET Core web applications (To...
4Developers 2018: Real-time capabilities in ASP.NET Core web applications (To...4Developers 2018: Real-time capabilities in ASP.NET Core web applications (To...
4Developers 2018: Real-time capabilities in ASP.NET Core web applications (To...
 

More from AbhishekMondal42

Oss evaluation-certification-oss-financial-advantages
Oss evaluation-certification-oss-financial-advantagesOss evaluation-certification-oss-financial-advantages
Oss evaluation-certification-oss-financial-advantages
AbhishekMondal42
 
Word press 01
Word press 01Word press 01
Word press 01
AbhishekMondal42
 
Word press posts(preview & publish)
Word press posts(preview & publish)Word press posts(preview & publish)
Word press posts(preview & publish)
AbhishekMondal42
 
Word press posts(add , edit , delete post)
Word press posts(add , edit , delete post)Word press posts(add , edit , delete post)
Word press posts(add , edit , delete post)
AbhishekMondal42
 
Word press pages(edit and delete)
Word press pages(edit and delete)Word press pages(edit and delete)
Word press pages(edit and delete)
AbhishekMondal42
 
Word press pages(add)
Word press pages(add)Word press pages(add)
Word press pages(add)
AbhishekMondal42
 
Word press media(add,insert,delete)
Word press media(add,insert,delete)Word press media(add,insert,delete)
Word press media(add,insert,delete)
AbhishekMondal42
 
Word press media library
Word press media libraryWord press media library
Word press media library
AbhishekMondal42
 
Word press widget management
Word press  widget managementWord press  widget management
Word press widget management
AbhishekMondal42
 
Word press view plugins
Word press  view pluginsWord press  view plugins
Word press view plugins
AbhishekMondal42
 
Word press user roles
Word press  user rolesWord press  user roles
Word press user roles
AbhishekMondal42
 
Word press theme management
Word press  theme managementWord press  theme management
Word press theme management
AbhishekMondal42
 
Word press personal profile
Word press  personal profileWord press  personal profile
Word press personal profile
AbhishekMondal42
 
Word press moderate comments
Word press  moderate commentsWord press  moderate comments
Word press moderate comments
AbhishekMondal42
 
Word press install plugins
Word press  install pluginsWord press  install plugins
Word press install plugins
AbhishekMondal42
 
Word press edit users
Word press  edit usersWord press  edit users
Word press edit users
AbhishekMondal42
 
Word press edit tags
Word press  edit tagsWord press  edit tags
Word press edit tags
AbhishekMondal42
 
Word press edit links
Word press  edit linksWord press  edit links
Word press edit links
AbhishekMondal42
 
Word press edit comments
Word press  edit commentsWord press  edit comments
Word press edit comments
AbhishekMondal42
 
Word press delete users
Word press  delete usersWord press  delete users
Word press delete users
AbhishekMondal42
 

More from AbhishekMondal42 (20)

Oss evaluation-certification-oss-financial-advantages
Oss evaluation-certification-oss-financial-advantagesOss evaluation-certification-oss-financial-advantages
Oss evaluation-certification-oss-financial-advantages
 
Word press 01
Word press 01Word press 01
Word press 01
 
Word press posts(preview & publish)
Word press posts(preview & publish)Word press posts(preview & publish)
Word press posts(preview & publish)
 
Word press posts(add , edit , delete post)
Word press posts(add , edit , delete post)Word press posts(add , edit , delete post)
Word press posts(add , edit , delete post)
 
Word press pages(edit and delete)
Word press pages(edit and delete)Word press pages(edit and delete)
Word press pages(edit and delete)
 
Word press pages(add)
Word press pages(add)Word press pages(add)
Word press pages(add)
 
Word press media(add,insert,delete)
Word press media(add,insert,delete)Word press media(add,insert,delete)
Word press media(add,insert,delete)
 
Word press media library
Word press media libraryWord press media library
Word press media library
 
Word press widget management
Word press  widget managementWord press  widget management
Word press widget management
 
Word press view plugins
Word press  view pluginsWord press  view plugins
Word press view plugins
 
Word press user roles
Word press  user rolesWord press  user roles
Word press user roles
 
Word press theme management
Word press  theme managementWord press  theme management
Word press theme management
 
Word press personal profile
Word press  personal profileWord press  personal profile
Word press personal profile
 
Word press moderate comments
Word press  moderate commentsWord press  moderate comments
Word press moderate comments
 
Word press install plugins
Word press  install pluginsWord press  install plugins
Word press install plugins
 
Word press edit users
Word press  edit usersWord press  edit users
Word press edit users
 
Word press edit tags
Word press  edit tagsWord press  edit tags
Word press edit tags
 
Word press edit links
Word press  edit linksWord press  edit links
Word press edit links
 
Word press edit comments
Word press  edit commentsWord press  edit comments
Word press edit comments
 
Word press delete users
Word press  delete usersWord press  delete users
Word press delete users
 

Recently uploaded

Data Structure using C by Dr. K Adisesha .ppsx
Data Structure using C by Dr. K Adisesha .ppsxData Structure using C by Dr. K Adisesha .ppsx
Data Structure using C by Dr. K Adisesha .ppsx
Prof. Dr. K. Adisesha
 
Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...
PsychoTech Services
 
Geography as a Discipline Chapter 1 __ Class 11 Geography NCERT _ Class Notes...
Geography as a Discipline Chapter 1 __ Class 11 Geography NCERT _ Class Notes...Geography as a Discipline Chapter 1 __ Class 11 Geography NCERT _ Class Notes...
Geography as a Discipline Chapter 1 __ Class 11 Geography NCERT _ Class Notes...
ImMuslim
 
Oliver Asks for More by Charles Dickens (9)
Oliver Asks for More by Charles Dickens (9)Oliver Asks for More by Charles Dickens (9)
Oliver Asks for More by Charles Dickens (9)
nitinpv4ai
 
220711130083 SUBHASHREE RAKSHIT Internet resources for social science
220711130083 SUBHASHREE RAKSHIT  Internet resources for social science220711130083 SUBHASHREE RAKSHIT  Internet resources for social science
220711130083 SUBHASHREE RAKSHIT Internet resources for social science
Kalna College
 
How to Setup Default Value for a Field in Odoo 17
How to Setup Default Value for a Field in Odoo 17How to Setup Default Value for a Field in Odoo 17
How to Setup Default Value for a Field in Odoo 17
Celine George
 
Temple of Asclepius in Thrace. Excavation results
Temple of Asclepius in Thrace. Excavation resultsTemple of Asclepius in Thrace. Excavation results
Temple of Asclepius in Thrace. Excavation results
Krassimira Luka
 
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptxRESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
zuzanka
 
220711130100 udita Chakraborty Aims and objectives of national policy on inf...
220711130100 udita Chakraborty  Aims and objectives of national policy on inf...220711130100 udita Chakraborty  Aims and objectives of national policy on inf...
220711130100 udita Chakraborty Aims and objectives of national policy on inf...
Kalna College
 
CHUYÊN ĐỀ ÔN TẬP VÀ PHÁT TRIỂN CÂU HỎI TRONG ĐỀ MINH HỌA THI TỐT NGHIỆP THPT ...
CHUYÊN ĐỀ ÔN TẬP VÀ PHÁT TRIỂN CÂU HỎI TRONG ĐỀ MINH HỌA THI TỐT NGHIỆP THPT ...CHUYÊN ĐỀ ÔN TẬP VÀ PHÁT TRIỂN CÂU HỎI TRONG ĐỀ MINH HỌA THI TỐT NGHIỆP THPT ...
CHUYÊN ĐỀ ÔN TẬP VÀ PHÁT TRIỂN CÂU HỎI TRONG ĐỀ MINH HỌA THI TỐT NGHIỆP THPT ...
Nguyen Thanh Tu Collection
 
INTRODUCTION TO HOSPITALS & AND ITS ORGANIZATION
INTRODUCTION TO HOSPITALS & AND ITS ORGANIZATION INTRODUCTION TO HOSPITALS & AND ITS ORGANIZATION
INTRODUCTION TO HOSPITALS & AND ITS ORGANIZATION
ShwetaGawande8
 
skeleton System.pdf (skeleton system wow)
skeleton System.pdf (skeleton system wow)skeleton System.pdf (skeleton system wow)
skeleton System.pdf (skeleton system wow)
Mohammad Al-Dhahabi
 
adjectives.ppt for class 1 to 6, grammar
adjectives.ppt for class 1 to 6, grammaradjectives.ppt for class 1 to 6, grammar
adjectives.ppt for class 1 to 6, grammar
7DFarhanaMohammed
 
CapTechTalks Webinar Slides June 2024 Donovan Wright.pptx
CapTechTalks Webinar Slides June 2024 Donovan Wright.pptxCapTechTalks Webinar Slides June 2024 Donovan Wright.pptx
CapTechTalks Webinar Slides June 2024 Donovan Wright.pptx
CapitolTechU
 
Simple-Present-Tense xxxxxxxxxxxxxxxxxxx
Simple-Present-Tense xxxxxxxxxxxxxxxxxxxSimple-Present-Tense xxxxxxxxxxxxxxxxxxx
Simple-Present-Tense xxxxxxxxxxxxxxxxxxx
RandolphRadicy
 
Information and Communication Technology in Education
Information and Communication Technology in EducationInformation and Communication Technology in Education
Information and Communication Technology in Education
MJDuyan
 
Skimbleshanks-The-Railway-Cat by T S Eliot
Skimbleshanks-The-Railway-Cat by T S EliotSkimbleshanks-The-Railway-Cat by T S Eliot
Skimbleshanks-The-Railway-Cat by T S Eliot
nitinpv4ai
 
BPSC-105 important questions for june term end exam
BPSC-105 important questions for june term end examBPSC-105 important questions for june term end exam
BPSC-105 important questions for june term end exam
sonukumargpnirsadhan
 
Educational Technology in the Health Sciences
Educational Technology in the Health SciencesEducational Technology in the Health Sciences
Educational Technology in the Health Sciences
Iris Thiele Isip-Tan
 
How to Download & Install Module From the Odoo App Store in Odoo 17
How to Download & Install Module From the Odoo App Store in Odoo 17How to Download & Install Module From the Odoo App Store in Odoo 17
How to Download & Install Module From the Odoo App Store in Odoo 17
Celine George
 

Recently uploaded (20)

Data Structure using C by Dr. K Adisesha .ppsx
Data Structure using C by Dr. K Adisesha .ppsxData Structure using C by Dr. K Adisesha .ppsx
Data Structure using C by Dr. K Adisesha .ppsx
 
Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...Gender and Mental Health - Counselling and Family Therapy Applications and In...
Gender and Mental Health - Counselling and Family Therapy Applications and In...
 
Geography as a Discipline Chapter 1 __ Class 11 Geography NCERT _ Class Notes...
Geography as a Discipline Chapter 1 __ Class 11 Geography NCERT _ Class Notes...Geography as a Discipline Chapter 1 __ Class 11 Geography NCERT _ Class Notes...
Geography as a Discipline Chapter 1 __ Class 11 Geography NCERT _ Class Notes...
 
Oliver Asks for More by Charles Dickens (9)
Oliver Asks for More by Charles Dickens (9)Oliver Asks for More by Charles Dickens (9)
Oliver Asks for More by Charles Dickens (9)
 
220711130083 SUBHASHREE RAKSHIT Internet resources for social science
220711130083 SUBHASHREE RAKSHIT  Internet resources for social science220711130083 SUBHASHREE RAKSHIT  Internet resources for social science
220711130083 SUBHASHREE RAKSHIT Internet resources for social science
 
How to Setup Default Value for a Field in Odoo 17
How to Setup Default Value for a Field in Odoo 17How to Setup Default Value for a Field in Odoo 17
How to Setup Default Value for a Field in Odoo 17
 
Temple of Asclepius in Thrace. Excavation results
Temple of Asclepius in Thrace. Excavation resultsTemple of Asclepius in Thrace. Excavation results
Temple of Asclepius in Thrace. Excavation results
 
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptxRESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
 
220711130100 udita Chakraborty Aims and objectives of national policy on inf...
220711130100 udita Chakraborty  Aims and objectives of national policy on inf...220711130100 udita Chakraborty  Aims and objectives of national policy on inf...
220711130100 udita Chakraborty Aims and objectives of national policy on inf...
 
CHUYÊN ĐỀ ÔN TẬP VÀ PHÁT TRIỂN CÂU HỎI TRONG ĐỀ MINH HỌA THI TỐT NGHIỆP THPT ...
CHUYÊN ĐỀ ÔN TẬP VÀ PHÁT TRIỂN CÂU HỎI TRONG ĐỀ MINH HỌA THI TỐT NGHIỆP THPT ...CHUYÊN ĐỀ ÔN TẬP VÀ PHÁT TRIỂN CÂU HỎI TRONG ĐỀ MINH HỌA THI TỐT NGHIỆP THPT ...
CHUYÊN ĐỀ ÔN TẬP VÀ PHÁT TRIỂN CÂU HỎI TRONG ĐỀ MINH HỌA THI TỐT NGHIỆP THPT ...
 
INTRODUCTION TO HOSPITALS & AND ITS ORGANIZATION
INTRODUCTION TO HOSPITALS & AND ITS ORGANIZATION INTRODUCTION TO HOSPITALS & AND ITS ORGANIZATION
INTRODUCTION TO HOSPITALS & AND ITS ORGANIZATION
 
skeleton System.pdf (skeleton system wow)
skeleton System.pdf (skeleton system wow)skeleton System.pdf (skeleton system wow)
skeleton System.pdf (skeleton system wow)
 
adjectives.ppt for class 1 to 6, grammar
adjectives.ppt for class 1 to 6, grammaradjectives.ppt for class 1 to 6, grammar
adjectives.ppt for class 1 to 6, grammar
 
CapTechTalks Webinar Slides June 2024 Donovan Wright.pptx
CapTechTalks Webinar Slides June 2024 Donovan Wright.pptxCapTechTalks Webinar Slides June 2024 Donovan Wright.pptx
CapTechTalks Webinar Slides June 2024 Donovan Wright.pptx
 
Simple-Present-Tense xxxxxxxxxxxxxxxxxxx
Simple-Present-Tense xxxxxxxxxxxxxxxxxxxSimple-Present-Tense xxxxxxxxxxxxxxxxxxx
Simple-Present-Tense xxxxxxxxxxxxxxxxxxx
 
Information and Communication Technology in Education
Information and Communication Technology in EducationInformation and Communication Technology in Education
Information and Communication Technology in Education
 
Skimbleshanks-The-Railway-Cat by T S Eliot
Skimbleshanks-The-Railway-Cat by T S EliotSkimbleshanks-The-Railway-Cat by T S Eliot
Skimbleshanks-The-Railway-Cat by T S Eliot
 
BPSC-105 important questions for june term end exam
BPSC-105 important questions for june term end examBPSC-105 important questions for june term end exam
BPSC-105 important questions for june term end exam
 
Educational Technology in the Health Sciences
Educational Technology in the Health SciencesEducational Technology in the Health Sciences
Educational Technology in the Health Sciences
 
How to Download & Install Module From the Odoo App Store in Odoo 17
How to Download & Install Module From the Odoo App Store in Odoo 17How to Download & Install Module From the Odoo App Store in Odoo 17
How to Download & Install Module From the Odoo App Store in Odoo 17
 

Html web messaging

  • 2. Web messaging is the ability to send real time messages from the server to the client browser. It overrides the cross domain communication problem in different domains, protocols or ports For example, you want to send the data from your page to ad container which is placed at iframe or voice-versa, in this scenario, Browser throws a security exception. With web messaging we can pass the data across as a message event. Message Event Message events fires Cross-document messaging, channel messaging, server- sent events and web sockets.it has described by Message Event interface.
  • 3. Sr.No Attributes and Description 1 data Contains string data 2 origin Contains Domain name and port 3 lastEventId Contains unique identifier for the current message event 4 source Contains to A reference to the originating document's window 5 ports Contains the data which is sent by any message port Attributes
  • 4. Sending a cross-document message Before send cross document message, we need to create a new web browsing context either by creating new iframe or new window. We can send the data using with postMessage() and it has two arguments. They are as  message - The message to send  targetOrigin - Origin name Examples
  • 5. Sending message from iframe to button var iframe document . querySe1ector( I iframe ' ) ; var button document . querySe1ector( I button ' ) ; var clickHand1er function() { iframe.contentWindow. postMessage( 'The message to send. ' ' https : / /www.texamine . com) ; button . addEventListener( ' click , clickHand1er, false) ; Receiving a cross-document message in the receiving document var messageEventHand1er function (event) { // check that the origin is one we want. if (event . origin I https://www.texamine.com l ) { alert (event . data) window. addEventListener( message ' messageEventHand1er, false)
  • 6. Channel messaging Two-way communication between the browsing contexts is called channel messaging. It is useful for communication across multiple origins. The MessageChanneI and MessagePort Objects While creating messageChannel, it internally creates two ports to sending the data and forwarded to another browsing context.  postMessage() - Post the message throw channel  start() - It sends the data  close() - It close the ports In this scenario, we are sending the data from one iframe to another iframe. Here we are invoking the data in function and passing the data to DOM.
  • 7. var loadHand1er function() { var mc, portMessageHand1er; mc new MessageChanne1(); window. parent . postMessage( ' documentAHasLoaded ' , ' http://foo.example' , [mc . port 2] ) ; portMessageHand1er function(portMsgEvent) { alert( portMsgEvent.data ) ; mc . portl. addEventListener( I message' , portMessageHand1er, false) mc . portl. start(); window. addEventListener( ' DOMContentLoaded ' , loadHand1er, false)
  • 8. Above code, it is taking the data from port 2, now it will pass the data to second iframe var loadHand1er function() { var i frames, messageHand1er; iframes = window. frames; messageHand1erfunction(messageEvent) { if( messageEvent.ports.1ength > e ) { // transfer the port to iframe[l] iframes [1] . postMessage( ' portopen' , ' http://foo.example ' , messageEvent . ports) ; window. addEventListener( ' message ' , messageHand1er, false) ; window. addEventListener( ' DOMContentLoaded , loadHand1er, false) ;
  • 9. Now second document handles the data by using the portMsgHandler function. var loadHand1er() { // Define our message handler function var messageHand1er function(messageEvent) { // Our form submission handler var formHand1er function() { var msg ' add to game circle. ' messageEvent . ports [0] . postMessage(msg) ; document . forms [0] . addEventListener( submit I , formHand1er, false) ; window. addEventListener( ' message ' , messageHand1er, false) ; window. addEventListener( ' DOMContentLoaded , loadHand1er, false) ;