这是:
var contents = document.getElementById('contents');
Run Code Online (Sandbox Code Playgroud)
与此相同:
var contents = $('#contents');
Run Code Online (Sandbox Code Playgroud)
鉴于jQuery已加载?
我正在尝试将消息从父窗口发布到它打开的子窗口。然而,该消息并未被发布。
在父窗口脚本中:
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)