Click to See Complete Forum and Search --> : resizing an open window or waiting till page loads before openning it


dimamo1983
09-10-2003, 09:33 PM
I would like to display a picture in a new window each time a thumb is clicked. Pretty standard thing to do. I have one catch though. I would like to have a function that automatically determines the size of the window so all I need to pass to it is the location of the picture file. No sizes, nothing else.

I found the scipt on javascriptsource that shows how to do it:
...
var pic = new Image();
pic.src = (url);
var windowWidth = pic.width + 20;
var windowHeight = pic.height + 70;
window.open...

And it works fine. Except there seems to be a catch. When I first click on a thumb, it opens a 20x70 window and then loads the picture which is of course bigger than that, so I have to either scroll or manually resize the window.
When I click on the thumb the second time, everything is fine. Now, I understand that this is caused by the picture being stored in the temp folder somewhere after it's loaded once, so whenever I click on the thumb after that, it can get the size and display it correctly. However, when I click it the first time, the picture has not been downloaded before the window is openned, that's why the window is only 20x70.

My question is if there is any workarounds for this initial load?
Can I have some kind of a delay function to wait until the picture is downloaded to temp and then get the size and display it? Or can I resize the window after the picture is loaded? Or something else?

thanks
dima

Khalid Ali
09-11-2003, 09:41 AM
yes you can use
setTimeout() function

dimamo1983
09-11-2003, 01:24 PM
hmmm, I tried that:

function ShowPicture (url)
{
var pic = new Image();
pic.src = (url);

setTimeout(10000);

var windowWidth = pic.width + 20;
var windowHeight = pic.height + 70;

and it did nothing and status bar shows an error wheneve I click on the thumb.
removed it and everything is back to normal..

am I using it correctly?

dimamo1983
09-11-2003, 01:26 PM
just tried doing setTimeout(pic,10000);
it openned a new window right away, without a delay and just like before, only 20x70...