简体   繁体   中英

How to have jQuery refer to a newly popped up window?

In the django function showRelatedObjectLookupPopup, I'd like to bind a function to a button in the newly popped up window, but I don't know how to refer to the new window. Here is what I have tried:

function showRelatedObjectLookupPopup(triggeringLink) {
// other function stuff omitted
    var name = triggeringLink.id.replace(/^lookup_/, '');
    name = id_to_windowname(name);
    var win = window.open(href, name, 500, 700, resizable=yes, scrollbars=yes');

    win.onload = function () {
         $(document).ready(function() {
               $("input.default").hover(function () {alert('hovered')})})};
    win.focus();
    return false;
}

But this binds to the button in the original window.

I think you are referring to the current window's document when you use

win.onload = function() { $(document).ready(...

try this:

win.onload = function() { $(win.document).ready(...

and likewise, give a context to your input selector:

 $("input.default", win.document).hover(...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM