I am attempting to post a message from a parent window to a child window it opens. However, the message is not getting posted.
In the parent window script:
function editAnnotation(annotKey){
var annotString = annotToString();
//open up the child window addAnnot.html.
var editAnnotWindow = window.open("editAnnot.html", "Ratting","width=200,height=400,0,status=0,scrollbars=1");
//send a message containing all the info from the current field. This message will cause all the fields to be prepopulated w info from annotation
editAnnotWindow.postMessage(annotString, '*');
}
In the child window script:
window.onload = addListeners();
/***********************************************************************
*
* Function that adds listeners for messages
*
*/
function addListeners() {
console.log("addListeners() called");
window.addEventListener('message', parseMessage, false);//listens for messages from the index.html file page
}
function parseMessage(event){
console.log("parseMessage() called");
}
addListeners() called
is logged, but parseMessage() called
is not.
I have already tried:
Changing the order of the functions.
Posting the message when the child window is opened.
E.g.:
var newWindow = window.open("file.html").postMessage("message string", '*');