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
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
  • 6,684
  • 6
  • 45
  • 68
80
votes
7 answers

Javascript; communication between tabs/windows with same origin

I have two windows: window A and window B. window A and window B have same domain window A and window B doesn't have any parent window. Questions: Is it possible for window A to get a reference of window B? what is the most elegant way to…
brillout
  • 8,117
  • 9
  • 60
  • 74
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,217
  • 3
  • 13
  • 11
63
votes
1 answer

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
  • 3,015
  • 2
  • 18
  • 24
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…
27
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,001
  • 5
  • 31
  • 32
27
votes
4 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
  • 439
  • 1
  • 5
  • 11
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,325
  • 5
  • 22
  • 24
21
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…
21
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
  • 5,140
  • 14
  • 44
  • 87
21
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
  • 1,984
  • 3
  • 19
  • 26
20
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
  • 12,290
  • 27
  • 86
  • 127
20
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
  • 10,895
  • 6
  • 41
  • 62
19
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,759
  • 1
  • 15
  • 45
19
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
  • 191
  • 1
  • 3
1
2 3
52 53