Javascript: Communications between Window & Iframe Using postMessage()

From Iframe to Window:

//The "*" can be a domain name to enhance the security
//The receiver can check the incoming message before executing any funcions.
parent.postMessage('SomeText', '*'); 

From Window to Iframe:

var frame = document.getElementById('frame'); 
frame.contentWindow.postMessage('SomeText', '*');

Add Listening for the message events:

window.addEventListener('message', function(event) { 

Useful Resources: