小编Yog*_*ort的帖子

postMessage() 到子窗口无法发布

我正在尝试将消息从父窗口发布到它打开的子窗口。然而,该消息并未被发布。

在父窗口脚本中:

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, '*');
}
Run Code Online (Sandbox Code Playgroud)

在子窗口脚本中:

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){ …
Run Code Online (Sandbox Code Playgroud)

javascript postmessage

2
推荐指数
1
解决办法
2805
查看次数

标签 统计

javascript ×1

postmessage ×1