jQuery target different window/popup

陌路散爱 提交于 2019-12-11 11:34:28

问题


I have jQuery open a popup:

function idealPopUp(str){
    var url = str;
    var windowName = "idealPopUp";
    var windowSize = 'height=820,width=784,toolbar=no,scrollbars=yes';              
    window.open(url, windowName, windowSize);
    event.preventDefault();
}

can I, from the original window, have jQuery target that popup? I want to know when it closes. The content of the popup is from another site and I have no control over it's jas/html etc.

I have this in the original window to try and talk to the popup:

$(document).ready(function(){
    $('#idealPopUp').unload( function () {
        alert("BING");
    });
});

..

..

UPDATED FUNCTION:

function idealPopUp(url){
    var windowName = "idealPopUpWindow";
    var windowSize = 'height=820,width=704,toolbar=no,scrollbars=yes';

    var idealPopUpWindow = window.open(url, windowName, windowSize);

    $(idealPopUpWindow).unload( function () {
        alert("BING");
    });
    event.preventDefault();
}

回答1:


var otherWindow = window.open(url, windowName, windowSize);

is a window reference; now you can

$(otherWindow).unload(...);


来源:https://stackoverflow.com/questions/8521728/jquery-target-different-window-popup

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!