Show Image in a pop-up window using PHP and Javascript

If you want to show an image in a popup window using onclick event using javascript then use the simplest way:

Put this in the head section of html code


<script type="text/javascript">
function myWindow(i,t,wid,hei) {
var day= new Date();
var id = day.getTime();
//Full screen
var w = (window.width); 
var h = (window.height); 
/*
You can also use the original image height and width as
var w = wid+100; 
var h = hei+100; 
*/
var params = 'width='+(w-50)+',height='+(h-50)+',scrollbars,resizable';

var message='<html><head><title>'+i+'</title></head><body><h3 aligh="center">'+
'<div align="center"><img src="'+i+'" border="0" alt="'+t+'"><br>\
'+
'<hr width="100&#37;" size="1"><form><input type="button" onclick="javascript:window.close();" value="Close Window"><br>\
'+
'<hr width="100%" size="1"></form></div></body></html>\
';

var mywin = open('',id,params);
mywin.document.write(msg);
mywin.document.close();
}
</script> 

Now call this in your Image code as


<?php
/*Get Picture from database*/
$pic=$q['pic'];
?>
<a href="#" title="<?php echo $title;?>" onClick="myWindow('admin/upload/<?php echo $pic;?>','admin/upload/<?php echo $pic;?>',100);" return false;" title="<?php echo $title;?>"><img src="admin/upload/<?php echo $pic;?>" width="62" height="46"  border="0"  /></a>

:slight_smile: