The following code is run in a popup window. The popup display an image. The code loads the image, obtaining the source and alt text from the source window. The code also determines the image dimensions and then resizes the window according to the dimensions. I tried just about every combination of code you could imagine, but always hit problems with the image not actually having been loaded at the time I need the dimensions. onload didn’t work because the entire code needed to be placed in onload or it didn’t seem to function at all, hence the need for the “wait”.
the following code does work, but I have a few points I am slightly concerned about! ( My JS skills are almost non-existent!) I would appreciate some constructive comments on the code:
[QUOTE]
function resize()
{
temp=new Image();
temp.src = window.opener[“imgSrc”];
if (temp.complete){
document.mainImage.src=window.opener[“imgSrc”];
document.mainImage.alt=window.opener[“imgAlt”];
document.getElementById(“textCell”).innerHTML=window.opener[“imgAlt”];
popHeight=temp.height+220;
popWidth=temp.width+120;
window.resizeTo(popWidth,popHeight);
}
else {
window.setTimeout(‘resize()’, 100);
}
}
window.onload=resize;