PDA

View Full Version : javascript open new window to size of image


JaeSun
11-14-2002, 03:57 PM
is there a javascript, that when you click a link or image link, itll open up a window, and that window will change according to the size of the image?

BUT i dont want to create a page for each image ... if i did, then i could just create the javascript to change sizes for each page....

doy you get what im saying?

so this is what i want ...

page .... you click a link (which links to an image), and in the link is javascript to maybe open another window based on the image size that its linking to

is that possible?

Scoobs
11-15-2002, 11:52 AM
I know how to do it in PHP if you have access to it.

In php you can use the getimagesize() to get the size of the image then use the values it returns to create the size of the new window

JaeSun
11-15-2002, 12:22 PM
ya, i have PHP on my hosting account....im already using PHP require() codes for all my pages....

explain...hehe..please?

DA Master
11-15-2002, 01:08 PM
Ain't it just

<?php getimagesize(); ?>

scoutt
11-15-2002, 02:44 PM
or you can use javascript.

http://www.snippetlibrary.com/viewhtml.php?id=5&kid=20&siteid=85

JaeSun
11-15-2002, 03:22 PM
Originally posted by scoutt
or you can use javascript.

http://www.snippetlibrary.com/viewhtml.php?id=5&kid=20&siteid=85

i have already checked it.... but it seems that from the code that you link, it has this code:

'image.jpg','300','200','* * Click window to .... etc etc

well, if i have to put the 300 and 200 for the size for each link, i might as well just use any javascript open up in the size of the image ... right? or is this javascript working in a different way?

scoutt
11-15-2002, 03:41 PM
UI must not have picked the correct one. I know I saw it on my site somewhere. let me see if I can find it.

Scoobs
11-18-2002, 07:18 AM
Simple really do it like this......



<?

$size = getimagesize ("wedding.jpg");
echo "<script language='javascript'>window.open('link.html','window_name','width=$size[0], height=$size[1]');</script>";

?>



Voila!

shayta
03-04-2004, 06:31 PM
scoutt, you ever find the script to do what he's looking for?

scoutt
03-04-2004, 08:11 PM
no, that was like 2 years ago. just make a new thread and it should be answered pretty quick.

Willy Duitt
03-04-2004, 08:52 PM
For the archives:
<script type="text/javascript">
<!--//
function newImg(which){
var theImg = new Image();
theImg.src = which;
var imgw = theImg.width;
var imgh = theImg.height;

if(imgw<100){imgw = 100};
if(imgh<100){imgh = 100};

var ImgWin = window.open('','imgwin',config='height='+imgh+',width='+imgw+',top=0,left=100')
with(ImgWin.document){
writeln('<html><head><title>Display Image</title></head>');
writeln('<body onload="self.focus()" onblur="self.close()">');
writeln('<div style="text-align:center">');
writeln('<img src='+which+'></div>');
writeln('<div style="text-align:center;font-size:9px">');
writeln('<a href="#" onClick="self.close()">Close Me</a>');
writeln('</div></body></html>');
close();
}
}
//-->
</script>
</HEAD>

<BODY>
<a href="dynamicbook1.gif" onclick="newImg(this.href);return false"><img src="dynamicbook1.gif"></a>

.....Willy

shayta
03-04-2004, 09:44 PM
ya this is perfect. thanks so much!!

also, when i execute this function, it loads the image in a new window like it's suppose to, but there's a white border. any way to get rid of the border so the image fits perfectly in the window?

AND is there a way to center the window when it pops up?

thanks for any help!

JaeSun
05-22-2004, 11:02 PM
man, this is old!! my site is down for another redo .. hahaha

agent002
05-23-2004, 08:25 AM
Hi Shayta,
make it...
<script type="text/javascript">
<!--//
function newImg(which){
var theImg = new Image();
theImg.src = which;
var imgw = theImg.width;
var imgh = theImg.height;

if(imgw<100){imgw = 100};
if(imgh<100){imgh = 100};

var l = Math.round((screen.width - imgw) / 2);
var t = Math.round((screen.height - imgh) / 2);

var ImgWin = window.open('','imgwin',config='height='+imgh+',width='+imgw+',top='+t+',left='+l)
with(ImgWin.document){
writeln('<html><head><title>Display Image</title></head>');
writeln('<body onload="self.focus()" onblur="self.close()" style="margin: 0; padding: 0;">');
writeln('<div style="text-align:center">');
writeln('<img src='+which+'></div>');
writeln('<div style="text-align:center;font-size:9px">');
writeln('<a href="#" onClick="self.close()">Close Me</a>');
writeln('</div></body></html>');
close();
}
}
//-->
</script>

.....

<a href="dynamicbook1.gif" onclick="newImg(this.href);return false"><img src="dynamicbook1.gif"></a>

ultimaslair
09-23-2004, 06:52 PM
Sorry to bring up a somewhat old topic. But, I used the scripts mentioned above (though, I changed it a little). But even before I had changed it, when testing it, windows would sometimes not pop up in the proper size. For instance, I click on a link (an image) and the window that pops up is actually about 100 x 100, instead of 600 x 500, which it is the image size. The symptom is wierd, because it only happens on occasion, and I can't seem to figure out what is going on. Maybe it has something to do with my link? The link is a thumbnail image in the size of 100 x 100, and sometimes the window that pops up is also 100 x 100.

Any help would be greatly appreciated.


BTW, if you need to see what the problem is, check this link.

http://www.ultimaslair.com/artwork/pencil/pg2.htm