相关疑难解决方法(0)

document.getElementById vs jQuery $()

这是:

var contents = document.getElementById('contents');
Run Code Online (Sandbox Code Playgroud)

与此相同:

var contents = $('#contents');
Run Code Online (Sandbox Code Playgroud)

鉴于jQuery已加载?

javascript jquery jquery-selectors

584
推荐指数
10
解决办法
54万
查看次数

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
查看次数