[whatwg] reply() extension to postMessage()

Aaron Boodman aa at google.com
Thu Feb 14 08:30:15 PST 2008

On Thu, Feb 14, 2008 at 8:18 AM, Anne van Kesteren <annevk at opera.com> wrote:
>    e.reply(message)
>  is equivalent to
>    e.source.postMessage(message, e.origin)

If we're going to add reply, I would like to easily be able to get
replies to a specific message. So extend postMessage to accept a
callback, and then either have reply() call this callback. Like this:

// sender:
someWindow.postMessage("hello!", function(response) {
  alert("got response: " + response);

// receiver
window.addEventListener("message", function(e) {
  alert("got message: " + e.message);
  e.reply("good day");

This solves a real problem that we have experienced with workers
(which have the same messaging style interface as post-message). Which
is that you have to send message IDs in all your messages and stitch
them back together manually.

Sorry again if I got identifier names wrong in this message, I have
not been keeping up with the changes to postMessage.

- a

- a

More information about the whatwg mailing list