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

790 questions
18
votes
2 answers

Specifying multiple targetOrigin uris in postmessage

Window.postMessage() has a targetOrigin parameter that can be set to a URI (to ensure the message reaches only a specific url). It can also be set to * of course (not recommended), but is there a way to specify multiple URIs as allowed? At present…
Michael Berry
  • 61,291
  • 17
  • 134
  • 188
17
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
  • 171
  • 1
  • 1
  • 3
16
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) { …
rec
  • 2,011
  • 11
  • 31
  • 37
16
votes
1 answer

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
  • 14,226
  • 9
  • 29
  • 40
15
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,149
  • 14
  • 109
  • 140
14
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
  • 7,609
  • 6
  • 29
  • 38
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…
NeenuChandran
  • 556
  • 5
  • 15
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,627
  • 1
  • 13
  • 26
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
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
  • 141
  • 1
  • 1
  • 4
13
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