The SitePoint Forums have moved.

You can now find them here.
This forum is now closed to new posts, but you can browse existing content.
You can find out more information about the move and how to open a new account (if necessary) here.
If you get stuck you can get support by emailing forums@sitepoint.com

If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Autosizing popup to image size?

Hi -

I'm putting together an image gallery on my site, and have a javascript that is "supposed" to allow the visitor to click the thumbnail of an image and have it pop up in a new window that is automatically sized to the width and height (plus padding) of the image. It seems to work... kinda. Problem is, the first time a thumbnail is clicked, it doesn't size the window correctly. Clicking it after that it seems to work fine for the most part. Anyhow, I'm hoping someone can help me get this code working properly...

Also it seems to add an immense amount of extra width to the window in Netscape 6, and I haven't been able to test it in NS4 and other browsers besides IE6 as I just finished building this computer and haven't located where to download older versions yet hehe...

Re: Autosizing popup to image size?

Originally posted by AC Design
*edit: fixed img code so it wouldnt screw up forum layout

Lol. No you didn't!

Anyway, back to the topic:

Also it seems to add an immense amount of extra width to the window

This is possibly something to do with this:

Code:

width = var_image.width + 20;
height = var_image.height +30;

and the way in which NS renders sizes.

As for the actual script, then this has been discussed a lot... it is possible (try doing a search and it might bring something up) and is certainly possible with PHP, but whilst I find the script for you (I know it is available on www.javascriptsource.com) then it is possible to do with the fact that you reference the name of the image (myImage) in the code, but you don't in the image opening tag. You could try messing around with that to see if it helps.

The problem is that the Image has to load before its width/height is known, other wise it returns 0, and the popup windows defaults are used, which is 100/100 (unlike in typical JS the function doesn't wait for the Image to load(cache) before moving on).

I tried looping around till the image w/h aren't 0, but didn't have success with NS4/others. This is a very difficult script to write, although I got it to work fine with IE.