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
13
votes
3 answers

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 do exactly what I need: postMessage - works as…
Alon
  • 7,618
  • 18
  • 61
  • 99
12
votes
8 answers

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 the webpage) Website 2: https://example.com (Fully…
Ryflex
  • 5,559
  • 25
  • 79
  • 148
12
votes
1 answer

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.initCustomEvent("message", true, true, 'Hello…
Afshin Mehrabani
  • 33,262
  • 29
  • 136
  • 201
12
votes
4 answers

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: The navigator.serviceWorker.controller is always…
user24502
  • 1,662
  • 4
  • 16
  • 21
12
votes
2 answers

Sending message back with postmessage

I am currently making an application where it is neccessary to send information between two domains (will be on loading of the page). Website 1: Creates iFrame > Sends Postmessage to website 2 window.onload = function () { iframe =…
Mick
  • 174
  • 1
  • 1
  • 9
12
votes
5 answers

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).contentWindow.postMessage('test',…
Alex
  • 66,732
  • 177
  • 439
  • 641
11
votes
4 answers

SendMessage vs PostMessage + WaitForSingleObject

I was wondering what's the difference between calling SendMessage (which blocks) and calling PostMessage in conjunction with WaitForSingleObject. Thoughts?
Filip Frącz
  • 5,881
  • 11
  • 45
  • 67
11
votes
2 answers

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 make a whole lot of sense to me and the…
K. Alan Bates
  • 3,104
  • 5
  • 30
  • 54
11
votes
4 answers

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 message event but I am unable respond by using…
user2281966
  • 121
  • 2
  • 6
10
votes
1 answer

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 only on specific pages like…
ToddN
  • 2,901
  • 14
  • 56
  • 96
10
votes
1 answer

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: