Traversing/Manipulating new window from parent window with jquery

Posted by Anthony on Stack Overflow See other posts from Stack Overflow or by Anthony
Published on 2010-03-22T01:38:10Z Indexed on 2010/03/22 1:41 UTC
Read the original article Hit count: 645

Filed under:
|
|
|
|

I found a question already with a possible solution, but I had already tried the method suggested before reading it, and it even says it's inconsistent. So I guess I'm wondering why this doesn't work:

$("img").click(function() {
    var imgwindow = window.open('imgwin.html','','width=460,height=345');
    alert(imgwindow.find("img").attr("src"));
});

The goal is to set the new window's img to the same src as the image that the user clicked to open the new window. But in the above scenario, I'm just trying to tap into the new window to get what it's already-set src. I have imgwin.html already written with a default src for the image, so it should alert that url. Instead I just get undefined.

I also tried the following (which should be identical on the back end), but with the same results:

$("img").click(function() {
    var imgwindow = window.open('imgwin.html','','width=460,height=345');
    alert($("img",imgwindow).attr("src"));
});

I even tried variations of wrapping the imgwindow variable in $() in case somehow jquery wasn't picking up on the variable as a DOM element.

The only thing I can guess is that since window.open() is a method, jquery doesn't treat it like a DOM element, even though all documentation from basic javascript tutorials treat the variable as both a method to open the window and the pointer to the window's inner DOM.

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery