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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

image size for a popup window

Status
Not open for further replies.

zapster

Programmer
Jun 8, 2001
36
GB
Hi,

Is there away in finding out the size of an image in Javascript?

The reason why i ask is that i need to create a popup window with an image in. But the image changes every day and i don't have control on it size. What i would like is for the popup window to resize itself (hofully via javascript) to the size of the image.

Can this be done, if so how

Thanks

zapster
 
you could assign the image an id, then get its width and height and resize the window accordingly
[tt]
<img id=&quot;myImage&quot; src=&quot;image.jpg&quot;/>

<script language=&quot;javascript&quot;>
var i = document.getElementById(&quot;myImage&quot;);
// add 10% to compensate for window borders, toolbars etc
window.resizeTo((i.width * 1.1), (i.height * 1.1));
</script>
[/tt] =========================================================
while (!succeed) try();
-jeff
 
Thanks Jeff

That works Great

is there a way to find out the source (url) or the name of the image

i.e. if blank.gif is loaded i can close the window down as this would mean there is no popup window was required.

thanks once again

zapster
 
yes - use imageObject.src
[tt]
<img id=&quot;myImage&quot; src=&quot;image.jpg&quot;/>

<script language=&quot;javascript&quot;>
var i = document.getElementById(&quot;myImage&quot;);
var src = i.src;

// add 10% to compensate for window borders, toolbars etc
window.resizeTo((i.width * 1.1), (i.height * 1.1));
</script>
[/tt] =========================================================
while (!succeed) try();
-jeff
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top