View Full Version : Rezing image to popup issue?

01-22-2009, 12:18 PM
Hello and thanks for taking the time to help me,

how do I alter the following code so that the popup window is automatically sized the image?

Please consider I am a total novice so excuse any ignorance I may portray.

<script type="text/javascript">

// JK Pop up image viewer script- By JavaScriptKit.com
// Visit JavaScript Kit (http://javascriptkit.com)
// for free JavaScript tutorials and scripts
// This notice must stay intact for use

var popbackground="white" //specify backcolor or background image for pop window
var windowtitle="Artist Image" //pop window title

function detectexist(obj){
return (typeof obj !="undefined")

function jkpopimage(imgpath, popwidth, popheight, textdescription){

function getpos(){
leftpos=(detectexist(window.screenLeft))? screenLeft+document.body.clientWidth/2-popwidth/2 : detectexist(window.screenX)? screenX+innerWidth/2-popwidth/2 : 0
toppos=(detectexist(window.screenTop))? screenTop+document.body.clientHeight/2-popheight/2 : detectexist(window.screenY)? screenY+innerHeight/2-popheight/2 : 0
if (window.opera){

var winattributes='width='+popwidth+',height='+popheight+',resizable=yes,left='+leftpos+',top='+toppos
var bodyattribute=(popbackground.indexOf(".")!=-1)? 'background="'+popbackground+'"' : 'bgcolor="'+popbackground+'"'
if (typeof jkpopwin=="undefined" || jkpopwin.closed)
//getpos() //uncomment these 2 lines if you wish subsequent popups to be centered too
//jkpopwin.moveTo(leftpos, toppos)
jkpopwin.resizeTo(popwidth, popheight+30)
jkpopwin.document.write('<html><title>'+windowtitle+'</title><body '+bodyattribute+'><img src="'+imgpath+'" style="margin-bottom: 0.5em"><br />'+textdescription+'</body></html>')


Many Thanks:thumbsup:

01-22-2009, 01:15 PM
Reading the script, jkpopimage function accepts 4 arguments:

Image path

Window's width

Window's height

...and the text description.

...why not just pass the desired width/height on the function call:

<a href="#" onclick="jkpopimage('path_to_image','300','300','Dummy text'); return false;">Open Image</a>

Philip M
01-22-2009, 01:26 PM
See also:-


if you want to get the image's width/height and then make the pop-up window size to suit. In other words, the size of the pop-up window is dependent on the size of the image to be displayed, as opposed to displaying all images at a given fixed size.