我有两个窗口,第二个是弹出窗口,我想从父窗口触发一个事件(第一个是我有这个弹出窗口的链接)。
这是触发器的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代码..绑定事件未按预期触发。
提前致谢
答案 0 :(得分:1)
我之前做过这样的事情:
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");
请注意: