UofRtist
05-10-2003, 12:48 AM
I have lots of thumbnail images on lots of different pages. I'd like to make a single .js file with a generic function that takes an img src as input, preloads this large version of the thumbnail, gets its width and height, and opens a new window based on that size.
Not difficult to code, right? Except the image is not done preloading by the time I call its height and width! So the window ends up tiny and the image is too big for it.
Ultimately, I told the onclick to load the large image into a 1x1 image hidden on the thumbnail page. Then I gave that 1x1 an onload handler that caused the popup, reasoning that width and height must be accurate by then. Success! Except it doesn't work on Safari, Opera, or anything on a Mac. Plus, it seems like anyone who has disabled pop-ups ignores onload commands automatically?
I don't want to delay getting dimensions for some arbitrary time because it's inefficient, and I'd rather it were started by a complete load. I tried constantly checking (while !image.complete do nothing) but that sucks all processor power (oops). I don't want to use width and height of large images as arguments in the onclick because there are so many images and I plan to add more. I don't want to keep checking image.complete at an interval because it'd be cleaner if it were event-driven and because .complete isn't universally supported (only JS 1.1 and only some browsers).
The working version (in IE, Netscape, and Mozilla on PCs) can temporarily be found at http://www.robinpulver.com/test4.html . Two images are available and work just fine. Take a look, it's very simple coding.
I've been playing around with opening an existing .html file with an <img src="">, then changing the src and resizing the window... can't quite make that work either.
Is there a clean way to do this that's universal? Keep in mind I'm a beginner with all the foundations but none of the truly advanced or browser-specific knowledge. If there's no simple way, I'll just include the larger image dimensions in the onclick handler of the thumbnails; it just leaves room for error and requires much more work.
Thanks so much to any guru that can help...
Not difficult to code, right? Except the image is not done preloading by the time I call its height and width! So the window ends up tiny and the image is too big for it.
Ultimately, I told the onclick to load the large image into a 1x1 image hidden on the thumbnail page. Then I gave that 1x1 an onload handler that caused the popup, reasoning that width and height must be accurate by then. Success! Except it doesn't work on Safari, Opera, or anything on a Mac. Plus, it seems like anyone who has disabled pop-ups ignores onload commands automatically?
I don't want to delay getting dimensions for some arbitrary time because it's inefficient, and I'd rather it were started by a complete load. I tried constantly checking (while !image.complete do nothing) but that sucks all processor power (oops). I don't want to use width and height of large images as arguments in the onclick because there are so many images and I plan to add more. I don't want to keep checking image.complete at an interval because it'd be cleaner if it were event-driven and because .complete isn't universally supported (only JS 1.1 and only some browsers).
The working version (in IE, Netscape, and Mozilla on PCs) can temporarily be found at http://www.robinpulver.com/test4.html . Two images are available and work just fine. Take a look, it's very simple coding.
I've been playing around with opening an existing .html file with an <img src="">, then changing the src and resizing the window... can't quite make that work either.
Is there a clean way to do this that's universal? Keep in mind I'm a beginner with all the foundations but none of the truly advanced or browser-specific knowledge. If there's no simple way, I'll just include the larger image dimensions in the onclick handler of the thumbnails; it just leaves room for error and requires much more work.
Thanks so much to any guru that can help...