Display image in javascript pop up window in PHP problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Mo
Forum Newbie
Posts: 21
Joined: Thu Nov 06, 2003 7:21 am

Display image in javascript pop up window in PHP problem

Post by Mo »

I have PHP and Javascript together to display an image in a pup up window. All seems to be working correctly ecxept for one thing. Some of the pictures show up on the bottom right hand corner of the screen, a little off the screen. And the pop up window is larger than the image.

I think this happend only to pictures I haven viewed before. One I veiw the image once the problem never happens again for that image.

Do I need to preload the image or somthing with javascript

Code: Select all

<?php
echo "<a href="javascript:showPic('$dir/$image[$j]', '$image[$j]');">\n
<img src='$dir/$image[$j]' border='0' width='$image_width[$j]' height='$image_height[$j]'></a>\n"
?>
Javascript

Code: Select all

var picWin = null;
function showPic(pic, title)&#123;
	if (picWin &amp;&amp; !picWin.closed) picWin.close();
	pageDoc = '&lt;html&gt;&lt;head&gt;&lt;title&gt;'+title+'&lt;/title&gt;&lt;/head&gt;';
	pageDoc += '&lt;body marginwidth="0" marginheight="0" leftmargin="0" topmargin="0"&gt;';
	pageDoc += '&lt;A href="javascript:window.close()"&gt;&lt;img border=0 src="'+pic+'" alt="'+title+'"&gt;&lt;/a&gt;';
	pageDoc += '&lt;/body&gt;&lt;/html&gt;';
	thePic = new Image();
	thePic.src = pic;
	attr = 'width=' + thePic.width;
	attr += ', height=' + thePic.height;
	attr += ', left=' + (screen.availWidth/2 - thePic.width/2);
	attr += ', top='  + (screen.availHeight/2 - thePic.height/2);
	picWin = window.open('', 'picWin', attr);
	picWin.document.write(pageDoc);
&#125;
Mo
Forum Newbie
Posts: 21
Joined: Thu Nov 06, 2003 7:21 am

Post by Mo »

Can anyone help me with this?
User avatar
xisle
Forum Contributor
Posts: 249
Joined: Wed Jun 25, 2003 1:53 pm

Post by xisle »

add + 5 pixels to the image_height and width then pass those params to the function. Pop the window with those height and width atrributes..
Mo
Forum Newbie
Posts: 21
Joined: Thu Nov 06, 2003 7:21 am

Post by Mo »

I did this and it didn't fix my problem.

You can see the problem here http://babejordan.com/photo_imaging.php ... /airplane/.

I dont even know if I did it correctly. This is what my code looks like after the change:

Code: Select all

<?php
echo "<a href="javascript:showPic('$dir/$image[$j]', '$image[$j]');">\n 
<img src='$dir/$image[$j]' border='0' width='$image_width[$j]'+5 height='$image_height[$j]'+5></a>\n" 
?>
User avatar
Saethyr
Forum Contributor
Posts: 182
Joined: Thu Sep 25, 2003 9:21 am
Location: Wichita, Kansas USA
Contact:

Post by Saethyr »

I was just there and everything seems to functioning normally.

Saethyr
Mo
Forum Newbie
Posts: 21
Joined: Thu Nov 06, 2003 7:21 am

Post by Mo »

Try any of the links on this page:

http://babejordan.com/photos.php
Post Reply