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
117
votes
2 answers

Uncaught DOMException: Failed to execute 'postMessage' on 'Window': An object could not be cloned

I'm trying to call parent.postMessage(obj, 'whatever'); from within an iframe and I'm getting this error: Uncaught DOMException: Failed to execute 'postMessage' on 'Window': An object could not be cloned.
nieve
  • 4,601
  • 3
  • 20
  • 26
93
votes
8 answers

Is cross-origin postMessage broken in IE10?

I'm trying to make a trivial postMessage example work... in IE10 between windows/tabs (vs. iframes) across origins Remove any one of these conditions, and things work fine :-) But as far as I can tell, between-window postMessage only appears to…
Bosh
  • 8,138
  • 11
  • 51
  • 77
65
votes
2 answers

jQuery doesn't support postmessage event?

When I use jQuery event listener to handle message event, like below: $(window).on('message', function(e) { var data = e.data; // data = undefined }); data is undefined! I'm sure that I have passed data to current window. Because if I use…
stefan
  • 2,377
  • 3
  • 15
  • 11
44
votes
1 answer

How to postMessage into iFrame?

I am developing a Chrome extension to use with my own Web-application, processing Web-pages (including cross-domain ones), loaded into iFrame on my application's main page. So I have to send message, containing the URL of the page to be processed,…
44
votes
5 answers

Access localStorage from service worker

I want to periodically call an API from my service worker to send data stored in the localStorage. This data will be produced and saved in localStorage when a user browses my website. Consider it something like saving stats in localStorage and…
36
votes
5 answers

Can the PostMessage API be used to communicate with an Android WebView?

I usually use the HTML5 PostMessage API to communicate information from my iframed content to the parent frame. Recently I've had my content used inside an Android WebView (as far as I can tell this is the native-Android equivalent of an iframe). Is…
Brian Putnam
  • 599
  • 1
  • 5
  • 12
36
votes
7 answers

javascript: listen for postMessage events from specific iframe

I have multiple iframes in a page. Now I have one message event listener for the page, which gets the messages from all of the iframes. I have a workaround to know from which iframe the message is coming. I would like to make event listeners for…
forresto
  • 12,078
  • 7
  • 45
  • 64
29
votes
4 answers

postMessage still broken on IE11?

It seems that window.postMessage is still broken on IE 11 when the message is between a window and a child popup/tab with window.open when it's sent from different domains [or same domain in some case, c.f. update 16/01] There was similar issues…
28
votes
4 answers

javascript postMessage not working

I don't know what to do. I tried several sample codes from different sources, I tried them in different browsers (from Chrome 9 to FF 4), and still nothing seems to be working with the "postMessage" function. JS console is giving me nothing, not a…
Cystack
  • 3,301
  • 5
  • 35
  • 33
28
votes
3 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
  • 70,193
  • 21
  • 157
  • 216
25
votes
2 answers

Any good debugger for HTML5 Javascript postMessage API?

Is there any good tool out there that allows developers to correctly debug messages sent between windows with postMessage? Or maybe a plugin for Firebug?
Pierre Duplouy
  • 2,415
  • 5
  • 23
  • 24
25
votes
1 answer

Uncaught SyntaxError: Failed to execute 'postMessage' on 'Window': Invalid target origin 'my_page' in a call to 'postMessage'

i have following script Parent Page(pair_pixel_filter.php): window.addEventListener("message", function(e) { $('#log').append("Received message: " + (e.data)); }, false); $('.photo-upload-btn').click(function(event) { …
noobie-php
  • 6,817
  • 15
  • 54
  • 101
23
votes
3 answers

How to make postMessage applicable to all subdomains

In window.postMessage second attribute specifies domain to which my message can be sent. Is there any way to specify that it is applicable to all subdomains. Things tried: iframe.contentWindow.postMessage('The message to…
user559126
  • 231
  • 1
  • 2
  • 3
22
votes
6 answers

postMessage Source IFrame

I'm working on a website with cross-domain iframes that are resized to the correct height using postMessage. The only problem I'm having is identifying which iframe has which height. The way I've currently got it set up is that when one iframe sends…
skimberk1
  • 2,064
  • 3
  • 21
  • 27
21
votes
4 answers

PostMessage with multiple functions or custom callbacks

So far I've only seen tutorials for postmessage where one window sends a single kind of message, and the other window interprets the message in only a single way. What if I want to have many different kinds of interactions between windows, can…
johnnietheblack
  • 13,050
  • 28
  • 95
  • 133
1
2 3
57 58