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

Dynamically sized pop-up windows with JS

Status
Not open for further replies.

quarryknight

Programmer
Jan 1, 2005
29
0
0
US
Hello, I am trying to great an onclick event for when an image thumbnail is clicked, a new window pops up to contain the exact dimensions of the image, with an an additional 50 pixels around the image. However, when I try to size the window according to the image's dimensions, it first pops up the window and passes the dimensions before the image is loaded. The user has to click the image twice to get the dimensions to pass correctly and resize the window.

Is there any way to correct this problem so that the dimensions are cast, even before the image is entirely loaded? Thanks for your time.

Find the best deals online!
 
Here's some code I once used. The popup window had one image in it and would resize itself after the image was loaded. You can customize this to your liking (the PHP code was because I used the same popup window over and over again):
Code:
<?
$imageURL = $_GET['url'];
?>
<html>
<head>
<title>Full Image</title>
<script language="JavaScript" type="text/javascript">
<!--
	var picUrl = '<?= $imageURL ?>';
	var NS = (navigator.appName == "Netscape")? true:false;

function FitPic() { 
	iWidth = (NS) ? window.innerWidth:document.body.clientWidth;
	iHeight = (NS) ? window.innerHeight:document.body.clientHeight;
	iWidth = document.images[0].width - iWidth;
	iHeight = document.images[0].height - iHeight + 30;
	window.resizeBy(iWidth, iHeight);
	self.focus();
}
//-->
</script>
</head>
<body onload="FitPic();" topmargin="0" marginheight="0" leftmargin="0" marginwidth="0">
<script language="JavaScript" type="text/javascript">
	document.write( "<img src='" + picUrl + "' border='0'>" );
</script>
<div align="center"><button type="button" onClick="self.close();">Close Window</button></div>
</body> 
</html>

HTH,

Jon

________________________________________
Give a man a match, he'll be warm for a minute. But light him on fire, and he'll be warm for the rest of his life.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top