I've been following this tutorial - http://www.youtube.com/watch?v=R2hOvZ7bwXU, which explains how to use postMessage to securely pass a message between iframe and parent - you basically end up with something like this - http://html5demos.com/postmessage2
My problem is that I need it to work the opposite way round (child to parent) and don't know how to target the parent window.
this is my receiver code (in the parent):
function handleMsg(e) {
if(e.origin == "http://uc.dialogue.net") {
let blah = e.data;
alert(blah);
} else {
alert("error");
}
}
addEventListener("message", handleMsg, true);
and this is the sender function that is triggered by a simple form (in child):
let text = document.querySelector('.srchInput').value;
window.parent.postMessage(text, "http://uc.dialogue.net");
Should I be targeting the parent in a different way?
Cheers
Paul
Question&Answers:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…