SlideShare a Scribd company logo
1 of 9
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 BottleZohar Arad
 
Windows 8 metro applications
Windows 8 metro applicationsWindows 8 metro applications
Windows 8 metro applicationsAlex 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
 
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 notificationsAlex Golesh
 
IPC mechanisms in windows
IPC mechanisms in windowsIPC mechanisms in windows
IPC mechanisms in windowsVinoth Raj
 
Websockets talk at Rubyconf Uruguay 2010
Websockets talk at Rubyconf Uruguay 2010Websockets talk at Rubyconf Uruguay 2010
Websockets talk at Rubyconf Uruguay 2010Ismael Celis
 
Socket Programming it-slideshares.blogspot.com
Socket  Programming it-slideshares.blogspot.comSocket  Programming it-slideshares.blogspot.com
Socket Programming it-slideshares.blogspot.comphanleson
 
Building interactivity with websockets
Building interactivity with websocketsBuilding interactivity with websockets
Building interactivity with websocketsWim Godden
 
Networking & Socket Programming In Java
Networking & Socket Programming In JavaNetworking & Socket Programming In Java
Networking & Socket Programming In JavaAnkur Agrawal
 
13 networking, mobile services, and authentication
13   networking, mobile services, and authentication13   networking, mobile services, and authentication
13 networking, mobile services, and authenticationWindowsPhoneRocks
 
Jsr120 sup
Jsr120 supJsr120 sup
Jsr120 supSMIJava
 
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-advantagesAbhishekMondal42
 
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 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 widget management
Word press  widget managementWord press  widget management
Word press widget managementAbhishekMondal42
 
Word press theme management
Word press  theme managementWord press  theme management
Word press theme managementAbhishekMondal42
 
Word press personal profile
Word press  personal profileWord press  personal profile
Word press personal profileAbhishekMondal42
 
Word press moderate comments
Word press  moderate commentsWord press  moderate comments
Word press moderate commentsAbhishekMondal42
 
Word press install plugins
Word press  install pluginsWord press  install plugins
Word press install pluginsAbhishekMondal42
 

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

Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingTeacherCyreneCayanan
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfAyushMahapatra5
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...Sapna Thakur
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 

Recently uploaded (20)

Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 

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) ;