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.
892
questions
125
votes
3
answers
160k
views
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 ...
103
votes
3
answers
186k
views
How do you use window.postMessage across domains?
It seems like the point of window.postMessage is to allow safe communication between windows/frames hosted on different domains, but it doesn't actually seem to allow that in Chrome.
Here's the ...
93
votes
8
answers
74k
views
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 ...
66
votes
2
answers
30k
views
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 ...
53
votes
1
answer
134k
views
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, ...
51
votes
5
answers
52k
views
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 ...
39
votes
7
answers
53k
views
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 ...
36
votes
5
answers
37k
views
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 ...
30
votes
5
answers
45k
views
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" ...
29
votes
3
answers
10k
views
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 ...
29
votes
4
answers
33k
views
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 ...
25
votes
1
answer
71k
views
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);
$('....
25
votes
2
answers
20k
views
Any good debugger for HTML5 Javascript postMessage API? [closed]
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?
24
votes
2
answers
6k
views
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) ...
23
votes
6
answers
24k
views
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 ...
23
votes
3
answers
13k
views
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....
22
votes
2
answers
31k
views
window.postMessage not working from iframe to parent document [duplicate]
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....
21
votes
4
answers
40k
views
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 ...
20
votes
3
answers
3k
views
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 ...
19
votes
2
answers
43k
views
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 ...
19
votes
3
answers
4k
views
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 ...
17
votes
3
answers
23k
views
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
}
...
16
votes
1
answer
13k
views
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....
16
votes
1
answer
41k
views
Does window.addEventListener('message') overwrite other listeners? [duplicate]
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:
...
16
votes
1
answer
46k
views
"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 ...
14
votes
4
answers
25k
views
Chrome ServiceWorker postMessage
I try to postMessage between a web application and the corresponding service worker. The service worker is successfully registered and working so far.
Unfortunately, I noticed some strange behavior:
...
14
votes
1
answer
5k
views
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 (chrome-...
14
votes
2
answers
7k
views
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:
<html>
<body>
<h1>Test</h1>
<h2>Outside</h2>
<...
14
votes
1
answer
10k
views
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 ...
14
votes
1
answer
2k
views
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( ...
14
votes
1
answer
1k
views
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:...
13
votes
1
answer
5k
views
Difference between custom event and postMessage
In order to send a message to another document (let's say an iframe), you can use both postMessage and createEvent functions. Assume this:
var event = document.createEvent('CustomEvent');
event....
13
votes
2
answers
12k
views
Sending message back with postmessage
I am currently making an application where it is neccessary to send information between two domains (will be on the loading of the page).
Website 1:
Creates iFrame >
Sends Postmessage to website 2
...
13
votes
1
answer
18k
views
Communicating cross-origin from parent to child iframe
I'm working through Third Party Javascript. I'm particularly interested in communication between a parent page and a child frame from a different origin. Using window.postMessage, it's trivial to ...
13
votes
3
answers
10k
views
How can I send an event from child window to its parent window
My main goal is:
Going to my application, open a link there in a new tab, make something in the new tab and send an event to the parent-main tab to refresh.
I have learned 2 techniques that doesn't ...
12
votes
5
answers
30k
views
How to execute a function through postMessage
I have this code inside a iframe:
window.addEventListener('message', function(e){
if(e.data == 'test')
console.log(e);
}, false);
and this inside the parent document:
$('#the_iframe').get(0)...
12
votes
4
answers
8k
views
detect which iframe sent post message
Assume I have several iframes on the page and one of them sent a post message. Is there a simple and crossbrowser way to detect which one did it and be able to reply?
I see the source property of the ...
12
votes
8
answers
7k
views
Allowing two sites to communicate to know the current URL of an iframe
I'm trying to figure out a solution to allow an website to know what URL the user is on through an iframe.
Website 1: http://website.website.com (Remote Website, can only add javascript & html to ...
11
votes
4
answers
12k
views
SendMessage vs PostMessage + WaitForSingleObject
I was wondering what's the difference between calling SendMessage (which blocks) and calling PostMessage in conjunction with WaitForSingleObject.
Thoughts?
11
votes
1
answer
6k
views
Why is using '*' as the targetOrigin for postMessage a security risk?
I'm having a hard time understanding the security issues when using a wildcard for the targetOrigin of the postMessage() method. Doesn't the window you call postMessage() on already have an origin ...
11
votes
2
answers
23k
views
window.postMessage between iframe and its parent with Angular: does anyone have a working example?
Does anyone have a working example of how to send and receive window.postMessage() calls in angular? I found the ng-post-message module on github and ngmodules, but I look at that code and it doesn't ...
11
votes
1
answer
18k
views
How can i get postmessage data from react?
I'm trying to load a react url as an iframe in my jsp project.
Here my sender side code block:
<iframe id="eda"
style="display: none;"
src="http://myhost:3000/"
...
10
votes
3
answers
27k
views
Issue communication with postMessage from parent to child iFrame
I'm having an issue communicating from my parent window to the child iFrame. But in the other side, everything works perfectly.
Here is how I get the chil iFrame object in order to fire the ...
10
votes
3
answers
8k
views
Send string data from Thread to main form
In Dephi, I create a thread, like this, which will send message to main form from time to time
Procedure TMyThread.SendLog(I: Integer);
Var
Log: array[0..255] of Char;
Begin
strcopy(@Log,PChar('...
10
votes
2
answers
33k
views
Cross-site iframe postMessage from child to parent
I found this sample from SO while browsing for my problem, but I want to know exactly how to use it in my scenario.
I have an iframe which is from another domain, and I want to detect when the iframe ...
10
votes
2
answers
12k
views
Can I do synchronous cross-domain communicating with window.postMessage?
I'm thinking of using window.postMessage directly for cross-domain communication.
If I do:
postMessage() from the parent frame
Load an iframe
window.addEventListener("message", callback, false); ...
10
votes
3
answers
24k
views
iframe cross domain messaging with jQuery postMessage plugin
I am trying to communicate between a child iframe and its parent using the following plugin:
http://benalman.com/projects/jquery-postmessage-plugin/
I can follow the example and post a message from ...
10
votes
1
answer
5k
views
Javascript Errors: "No relay set", only in IE 7, 8
My javascript won't load because of errors it receives, only in IE. I used debugger to get the following errors. This page renders the javascript correctly in Safari, FF and chrome but not in IE and ...
10
votes
1
answer
444
views
Use common JS libs inside sandboxed iframes
I plan to build a module system for my webapp that uses sandboxed iframes and the postMessage API to securely run custom user modules. The iframe blocks all DOM access and should only communicate ...
9
votes
2
answers
8k
views
javascript - window.postmessage - event.data is always null
I have an iframe and want to send data from the iframe to the parent window.
Inside the js code of the iframe, I have the following statement
window.parent.postMessage('hello', '*');
The ...