...

View Full Version : Help with centering a window popup



Errica
10-20-2005, 08:38 PM
Hi,

Can someone assist in modifying this code so that the popup is centered on the page?

function popImg(which){
var theImg = new Image();
theImg.src = which;
var imgw = theImg.width;
var imgh = theImg.height;

if(imgw<600){imgw = 600};
if(imgh<400){imgh = 400};

var imgWin = window.open('','popImg',config='height='+imgh+
',width='+imgw+',top=0,right=100');

mlse
10-20-2005, 08:50 PM
Try (screen.availHeight - imgh)/2.0 and (screen.availWidth - imgw)/2.0 for top and right, respectively.

Errica
10-20-2005, 09:27 PM
The following seems to work. If you see an extraneous code, please let me know?

function popImg(which){
var theImg = new Image();
theImg.src = which;
var imgw = theImg.width;
var imgh = theImg.height;
var w=(screen.width-600)/2;
var h=(screen.height-400)/2;

if(imgw<600){imgw = 600};
if(imgh<400){imgh = 400};

var imgWin = window.open('','popImg',config='height='+imgh+
',width='+imgw+',top='+h+',left='+w+'');



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum