Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Image.width Issue 1

Status
Not open for further replies.

Mugs321

Programmer
Jan 31, 2007
49
CA
Hey all,
I've found a solution to my problem using a different method but I still don't understand why my method didn't work.

I wanted to open a popup window to display a large image (when the thumbnail is clicked) and I wanted the size of the window to be relative to the size of the picture.

The alert below always returns 20 irregardless of the size of the image. Any ideas as to why the true width is not returned?

Code:
var popImg = new Image();
popImg.src = imgURL;

alert(popImg.width);
	
doPopup2(imgURL, popImg.width+10, popImg.height+10);
 
Hi

Code:
var popImg = new Image();
popImg.src = imgURL;

[gray]// are you sure the browser is able to establish the connection, make the request and receive the image in this short time ?[/gray]

alert(popImg.width);
    
doPopup2(imgURL, popImg.width+10, popImg.height+10);
The [tt]Image[/tt] object has [tt]complete[/tt] property and [tt]onload[/tt] event, but I had some bad experiences with them in ancient browsers. So I would use :
Code:
var popImg = new Image();
popImg.src = imgURL;

window.setTimeout('chkimg()',100);

function chkimg()
{
  if (popImg.width==0) {
    window.setTimeout('chkimg()',100)
    return
  }
  alert(popImg.width);
  doPopup2(imgURL, popImg.width+10, popImg.height+10);
}

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top