Opening an image in a popup: how to get its size when the image is loaded?
<p>I am writing a script that looks for links of the kind <code>&lt;a href='image_url'&gt;...&lt;/a&gt;</code>, where image_url is the url of an image, and then adds to those tags an <code>onclick='popupImage(this)'</code> attribute to them that opens a popup displaying the image. I know how to look for those tags, and my question is about writing the popupImage function. So far, I have</p>

<pre><code>function popupImage(link){
    window.open(link,'image','width=400,height=400'); 
}
</code></pre>

<p>This works pretty well, but I would like to resize the popup to fit the image, once it's loaded. Thus, I would probably need something of the kind</p>

<pre><code>function popupImage(link){
    w=window.open(link,'image','width=400,height=400');
    w.onload = function(){
        ... Do something to get the size of the image...
        ... Resize the popup (this, I know how to do)...
    }
}
</code></pre>

<p>But I don't know how to access the image loaded by the window, since it has no DOM... The thing is that I really don't want to write some HTML into the popup to display the image (for some other reasons).</p>

<p>Any suggestion would be much appreciated. Thanks in advance!</p>
