Forum Moderators: coopster

Message Too Old, No Replies

How to make a thumbnail open a new window

         

chaddsisco

1:59 pm on Sep 19, 2005 (gmt 0)

10+ Year Member



Here is what my gallery page code looks like right now. I would like to change it so that when a user clicks on one of the thumbnails the picture then opens fullsize in a window of its own, any ideas? Thanks...

<?php

//connect to the database
$link = mysql_connect("localhost", "admin", "pass")
or die("Could not connect: " . msql_error());
mysql_select_db("gallery", $link)
or die (mysql_error());

$ImageDir = "/ballooncrew/gallery/centerpieces/";
$ImageThumb = $ImageDir . "/thumbs/";

$max_cols = 4;
?>

<html>
<head>
<title>Welcome to our Centerpeices Photo Gallery</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></head>
<body bgcolor="#000000" text="#FFFFFF">
<p align="center">Click on any image to see it full sized.</p>
<table align="center">
<?php
// echo "<tr>";
// for ($i = 0; $i < $max_cols; $i+=1) {
// echo " <td align=\"center\">Image</td>";
// echo " <td align=\"center\">Caption</td>";
// echo " <td align=\"center\">Date Uploaded</td>";
//}
//echo "</tr>";
?>

<tr>
<?php
$counter = 0;
//get the thumbs
$getpic = mysql_query("SELECT * FROM gallery_centerpieces")
or die(mysql_error());
while ($rows = mysql_fetch_array($getpic)) {
extract($rows);
if ($counter % $max_cols == 0 && $counter!= 0) { echo "</tr><tr>\n"; }
echo "<td><a href=\"".$ImageDir . $image_id . ".jpg\">";
echo "<img src=\"" . $ImageThumb . $image_id . ".jpg\" border=\"0\">";
echo "</a></td>\n";
//echo "</tr>\n";
$counter += 1;
}

?>

</table>
</body>
</html>

omoutop

2:14 pm on Sep 19, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



do it in javascript...........simpler...

use this in head:

<SCRIPT LANGUAGE="JavaScript">

<!-- This script and many more are available free online at -->
<!-- The JavaScript Source! [javascript.internet.com...] -->

<!-- Begin
function CaricaFoto(img){
foto1= new Image();
foto1.src=(img);
Controlla(img);
}
function Controlla(img){
if((foto1.width!=0)&&(foto1.height!=0)){
viewFoto(img);
}
else{
funzione="Controlla('"+img+"')";
intervallo=setTimeout(funzione,20);
}
}
function viewFoto(img){
largh=foto1.width+20;
altez=foto1.height+20;
stringa="width="+largh+",height="+altez;
finestra=window.open(img,"",stringa);
}
// End -->
</script>
////////////////////////////////HEAD ENDS////

Call each image by using this example....

<A HREF="javascript:CaricaFoto('photos/<? echo $photo2?>')" alt="<? echo $desc2?>" BORDER="0">
<img src="photos/thumbs/<? echo $thumb2?>" alt="<? echo $desc2?>" width="150" height="113">
...................................................

hope it works 4 u, i know it is good cause I use it ...

chaddsisco

2:38 pm on Sep 19, 2005 (gmt 0)

10+ Year Member



Thanks for the script but that does not seem to do the trick for me, anyone else have any ideas?

dmmh

3:40 pm on Sep 19, 2005 (gmt 0)

10+ Year Member



change:

echo "<td><a href=\"".$ImageDir . $image_id . ".jpg\">";
echo "<img src=\"" . $ImageThumb . $image_id . ".jpg\" border=\"0\">";
echo "</a></td>\n";

to:
echo "<td><a href=\"http:www.host.com/".$ImageDir.$image_id.".jpg\" target=\"_blank\">";
echo "<img src=\"".$ImageThumb.$image_id."jpg\" border=\"0\" alt=\"image\" title=\"view image full screen\">";
echo "</a></td>\n";

should do the trick, no need for fancy javascript if HTML can do it :)
seems to me you arent quite into the html tags, as you neglected the ALT and TITLE attributes for the <img> tag. The ALT attribute is required, the title attribute a very handy optional attribute

the 'target' attribute for the <a> tag is very handy also and you also left it out
if you set it to "_SELF" it will open the image in the current window, if you set it to "_BLANK" it will open in a new window

omoutop

6:52 am on Sep 20, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Yeap, html can do it too easily....however, the javascript will open a new window with the exact dimensions of the actual photo...not just an ordinary window....if the photo is 150x100 then this will be the size of the window...if the photo is 640x480 then the window will be bigger and so on and so forth....

chaddsisco

12:34 pm on Sep 22, 2005 (gmt 0)

10+ Year Member



I changed my code to use the php version and that worked! Now my question is, can I make that window the same size as the photo or can that only be done using javascript?

omoutop

12:50 pm on Sep 22, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



you actually need both...u need javascript to open the window in to certain dimensions while u also need php in order to get the image dimensions...first get dimensions...then use js to open the window....

chaddsisco

1:00 pm on Sep 22, 2005 (gmt 0)

10+ Year Member



Gotcha, I was looking for a way to do this whole page without using javascript though. I just thought some one may know of a new to do it with just php.

dmmh

8:51 pm on Sep 22, 2005 (gmt 0)

10+ Year Member



no can do as far as I know, as you need to perform client-side operations (resize browser window) while PHP is strictly server-side :)

chaddsisco

11:36 am on Sep 23, 2005 (gmt 0)

10+ Year Member



damn, what a let down