Skip to content

Latest commit

 

History

History
20 lines (16 loc) · 591 Bytes

send-message-to-parent-window-from-iframe.md

File metadata and controls

20 lines (16 loc) · 591 Bytes

Send message to parent window from iframe or popup

Browsers provide the window.postMessage API for sending simple messages from an iframe to the parent window.

To send a message:

  window.parent.postMessage(JSON.stringify({ 
    src: window.location.toString(), 
    context: 'iframe.resize', 
  }), '*');

To listen for a message:

window.addEventListener("message", function(e) { 
  console.log(e) 
}, false);

Read the MDN documentation. Beware of the security implications.