I am writing a script that looks for links of the kind <a href='image_url'>...</a>
, where image_url is the url of an image, and then adds to those tags an onclick='popupImage(this)'
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
function popupImage(link){
window.open(link,'image','width=400,height=400');
}
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
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)...
}
}
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).
Any suggestion would be much appreciated. Thanks in advance!