[英]Trigger an event in the popup from a parent
我有兩個窗口,第二個窗口是一個彈出窗口,並且我想從父窗口觸發一個事件(第一個窗口有指向該彈出窗口的鏈接)。
這是觸發器的javascript代碼(在父窗口的javascript代碼中):
winPop=window.open(opts.url,opts.nom,"width="+opts.width+",height="+opts.height+",top="+opts.top+",left="+opts.left);
winPop.onload=function(){
$(winPop.document).trigger('connected', {
jid: "jid",
password: '123'
});
}
此JavaScript代碼啟動彈出窗口,並嘗試觸發綁定在彈出窗口(就緒)函數中的事件:
$(document).ready(function () {
$(document).bind('connected', function () {
alert("Hello , I'm here");
});
問題是使用先前的javascript代碼..綁定事件未按預期觸發。
提前致謝
我之前是這樣的:
var realWindowOpen = window.open;
window.open = wrappedWindowOpen;
function wrappedWindowOpen(url, name, specs, replace) {
window.open = realWindowOpen;
var windowHandle = window.open(url, name, specs, replace);
if (windowHandle)
console.log("New Popup Window created: ", {name:name});
else
console.error("New Window Failed. " + {name:name});
if (popupFnCreationNotify) {
popupFnCreationNotify(windowHandle);
popupFnCreationNotify = null;
}
window.open = wrappedWindowOpen;
}
// Calling example
var popupFnCreationNotify = function() {
console.log("I got called back");
};
window.open("my url");
請注意:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.