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.