using postmessage to refresh iframe’s parent document

Use:

window.parent.postMessage('Hello Parent Frame!', '*');

Note the ‘*’ indicates “any origin”. You should replace this with the target origin if possible.

In your parent frame you need:

window.addEventListener('message', receiveMessage, false);

function receiveMessage(evt)
{
  if (evt.origin === 'http://my.iframe.org')
  {
    alert("got message: "+evt.data);
  }
}

Replace “my.iframe.org” with the origin of your iFrame. (You can skip the origin verification, just be very careful what you do with the data you get).

Leave a Comment