Closed Thread Icon

Topic awaiting preservation: Center popup Pages that link to <a href="https://ozoneasylum.com/backlink?for=8209" title="Pages that link to Topic awaiting preservation: Center popup" rel="nofollow" >Topic awaiting preservation: Center popup\

 
Author Thread
Quarath
Bipolar (III) Inmate

From: Magna, UT
Insane since: May 2000

posted posted 06-08-2002 08:30

I am trying to have popup from a link be centered I am using this to call the popup page:

<a class="dark" href="#dummy" onclick="window.open('clients/chaotic.html','winscript','height=250,width=300,left=GetCenterLeft(left),top=GetCenterTop(top),toolbars=0'); return false">Chaotic Entertainment</a>

and I was hoping to try and make something like this work to calculate the center coordinates

function GetCenterLeft(num) {
// compute center coordinate
if(NN4&#0124; &#0124;NN6) {
num=Math.round((window.innerWidth/2)-(w/2))
} else {
num=Math.round((document.body.clientWidth/2)-(w/2))
}
}

function GetCenterTop(num) {
// compute center coordinate
if(NN4&#0124; &#0124;NN6) {

num=Math.round((window.innerHeight/2)-(h/2))
} else {
num=Math.round((document.body.clientHeight/2)-(h/2))
}
}

I'm no javascript guru so am I even close or is there an easier way to do this? I haven't currently got this posted online but I can if it helps.

kuckus
Bipolar (III) Inmate

From: Berlin (almost)
Insane since: Dec 2001

posted posted 06-08-2002 09:11

I guess you should have something like

return num;

at the end of both functions. Otherwise they calculate the positions without returning the calculated value.

kuckus (cell #282)

Hugh
Paranoid (IV) Inmate

From: Dublin, Ireland
Insane since: Jul 2000

posted posted 06-08-2002 16:54

I copied this from my site:

<a class="dark" href="#dummy" onclick="go('clients/chaotic.html',300,250); return false;">Chaotic Entertainment</a>

function go(url,tWidth,tHeight) {
gleft = (screen.width-tWidth)/2;
gtop = (screen.height-tHeight)/2;
popup = open(url,"gWindow",'toolbar=0,location=0,directories=0,status=1,menubar=0,scrollbars=1,resizable=1,width='+tWidth+',height='+tHeight+',left='+gleft+',top='+gtop+'');
}

That should help, unless you want the popup to be centered according to the browser window instead of the screen, then replace screen.width with the window.innerWidth .. what you have below (screen.width, is IE&NS4 compatable).

« BackwardsOnwards »

Show Forum Drop Down Menu