[Javascript] OPEN WINDOW TO EXACT SIZE

Rodney Myers rodney at aflyingstart.net
Thu Jun 7 06:47:40 CDT 2001



> I am opening a pop up window that displays an image. I need the window
> to be the exact size of the image. Is there a way to do this without
> knowing how big the image is going to be?


The file myimage.htm is popped and in MSIE will resize itself to fit the image
Image url is sent as query string (without any "name=" tag)
Here the image URLs are just file names but they may need to be longer or even
full http addresses

Thanks to Peter-Paul Koch <gassinaumasis at hotmail.com>
for the onload code

I have put the onload code into a function to reduce the risk of email line
breaks causing anyone copying the code a problem.


Popper.htm

<html><head>
<title>Popper</title>
<script language="JavaScript">
<!--

function openIMGwin(imgURL) {
var Wname = "popped";
var exec = 'window.open("';
// Set name of common html file here
var URL   = "myimage.htm?"+imgURL;
exec+= URL;      exec+= '", "';
exec+= Wname;    exec+= '", "';
// default dimensions set next line
exec+='width=400,height=400';
// 0,0 positions to top left
// top=0,left=0 does for MSIE
// screenX=0,screenY=0 does for Netscape
// other attributes set for a very plain window
// note that resizable=1 because
// Netscape 4.x users will have to resize manually
// NN6.x ??
exec+=',top=0,left=0,screenX=0,screenY=0,toolbar=0,location=0';
exec+=',directories=0,resizable=1,status=0,menubar=0,scrollbars=0")';
// eval() takes the string called exec built and executes as code
eval (exec);
}//

//--end-->
</script>
</head>
<body>
<!-- sort out your own image file names -->
<a href="javascript:openIMGwin('aaa.jpg')">aaa.jpg</a><br>
<a href="javascript:openIMGwin('bbb.jpg')">bbb.jpg</a><br>
</body></html>

myimage.htm

<html><head>
<title>Image</title>
</head>
<body onLoad="resizingWindow();">
<script language="JavaScript">
<!--
function resizingWindow(){
if(self.resizeTo)
 {self.resizeTo(document.images[0].width,
                document.images[0].height);}
}//

// Write Image tag with URL from search string
// substring(1) to skip the leading '?'
document.write('<IMG src="',
  window.location.search.substring(1),'">');

//--end-->
</script>

</body></html>

--
Shop at ssistant Add-ons and Developer Workshops
http://www.aflyingstart.net/addons/

Enquiries regarding Shop at ssistant Classic training :
Call 01256 880770

Rodney Myers
Based in Oxford, England
Technical Director, Shop at ssistant eCommerce Solutions

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.evolt.org/pipermail/javascript/attachments/20010607/65413a71/attachment.htm>


More information about the Javascript mailing list