Questions tagged [postmessage]

The window.postMessage() method safely enables cross-origin communication between Window objects; e.g., between a page and a pop-up that it spawned, or between a page and an iframe embedded within it.

Cross-document messaging (aka postMessage) is an API introduced in the WHATWG HTML5 draft specification, allowing documents to communicate with one another across different origins, or source domains. Prior to HTML5, Web browsers disallowed cross-site scripting, to protect against security attacks.

See MDN Window.postMessage() API Reference

Related APIs

863 questions
21
votes
2 answers

Does window.postMessage guarantee the order of events?

window.onmessage = ... window.postMessage('1', '*'); window.postMessage('2', '*'); Does postMessage (http://www.whatwg.org/specs/web-apps/current-work/multipage/webappapis.html#queue-a-task) guarantee the order of events?
4esn0k
  • 9,789
  • 7
  • 33
  • 40
21
votes
2 answers

window.postMessage not working from iframe to parent document

I'm trying to send a simple message from a child document (an iframe) back to its direct parent using the window.postMessage API. Within the parent document I have the following: window.addEventListener("message", receiveMessage, true); var…
chris.wilkinson
  • 211
  • 1
  • 2
  • 3
20
votes
3 answers

top.postMessage origin error not caught

I'm trying to implement communication with postMessage. There is the main page which opens a popup with an iframe which comes from a different domain. This works fine so far but I want to catch the following error which occurs when I open the iFrame…
Arikael
  • 1,989
  • 1
  • 23
  • 60
19
votes
2 answers

Problems with window.postMessage on Chrome

I have been stuck on this for hours. I have a.html on http://example.com that contains an iframe with src to b.html on http://subdomain.example.com. a.html has some JS code to postMessage to the iframe. The code to postMessage is…
user1437328
  • 15,546
  • 9
  • 34
  • 44
17
votes
3 answers

How to send a string via PostMessage?

Inside my app, I want to send a message to a dialog from a different thread. I want to pass an std::exception derived class reference to the dialog. Something like this: try { //do stuff } catch (MyException& the_exception) { …
LLucasAlday
  • 2,349
  • 11
  • 34
  • 41
16
votes
1 answer

"DataCloneError: The object could not be cloned." in FireFox 34

Using given function to post message, but getting error "DataCloneError: The object could not be cloned." at Line "target['postMessage'](message, target_url.replace( /([^:]+://[^/]+).*/, '$1'));" in FireFox-34, same code is working fine on Chrome…
Krishna
  • 161
  • 1
  • 1
  • 4
16
votes
1 answer

Does window.addEventListener('message') overwrite other listeners?

I've got some code that communicates with an iframe using .postMessage(), meaning it needs to add a listener on message to receive communication from the iframe. I'm using the usual code for that: window.addEventListener('message', processMessage,…
Chris Wilson
  • 6,599
  • 8
  • 35
  • 71
16
votes
1 answer

communication between two iframe children using postMessage

I have some embed code that users can put on their sites. It creates two children iframes on the page. I'd like to have those children be able to communicate. I'm using javascript's window.postMessage…
Brian Armstrong
  • 19,707
  • 17
  • 115
  • 144
15
votes
3 answers

Cross-domain, cross-tab communication between co-operating pages

Say I have two tabs, each with a web-page loaded on a different domain. The pages in the two tabs want to communicate. The simplest solution I could see was this one (my answer on a closely-related question I found while searching for duplicates),…
cloudfeet
  • 12,156
  • 1
  • 56
  • 57
14
votes
1 answer

Flutter Web listen to Events posted through iFrame

my goal is to integrate a flutter widget with the help of an iframe on my main page. The main page is not written in flutter. However, I need an interface through which the main page can communicate with the widget. So I thought of using…
Jannik
  • 635
  • 1
  • 6
  • 14
14
votes
1 answer

Uncaught DOMException: Failed to execute 'postMessage' on 'Window'

I'm getting error content-script.js:24 Uncaught (in promise) DOMException: Failed to execute 'postMessage' on 'Window': An object could not be cloned. at Object.t.messageJumpContext…
Neenu Chandran
  • 722
  • 1
  • 6
  • 18
14
votes
1 answer

Securing postMessage() on Cordova

My Cordova mobile app uses an iframe to load in a website. I want to send and receive contents over the iframe with postMessage(). However, through my testing my mobile app origin is always localhost:8000 or file://. Every other example on this site…
JM-AGMS
  • 1,670
  • 1
  • 15
  • 33
14
votes
1 answer

javascript - postMessage to sandboxed iframe, why is recipient window origin null?

2 postMessage calls in the test: 1 using an asterisk for targetOrigin, one using the same https url of both the parent and child documents. button 1: $('.iframed')[0].contentWindow.postMessage( messageData , '*' ); button…
Crite
  • 151
  • 5
14
votes
2 answers

PostMessage from a sandboxed iFrame to the main window, origin is always null

There's something I don't get about the event origin with javascript postMessage event. Here is my main page:

Test

Outside