...

View Full Version : How to center a popup window?



antimedia
10-20-2005, 01:40 PM
Hello I am using this script to open multiple popup windows of various sizes. The code was kindly provided by glenngv (thanks works great) but since they are various window sizes a static set dimension of where the window is placed wont work example: top=50, left=200' what I need is to find out how to center the popup no mater of the size of the popup

<script>
function popitup(url, w, h)
{
var newW = w + 100; //add border
var newH = h + 100; //add border
var newwindow=window.open(url, 'name', 'height='+newH+', width='+newW+', top=50, left=200');
newwindow.resizeTo(newW, newH); //if popup window is already open, the size specified in window.open does not take effect, so we need to resize it.
newwindow.focus();
return false;
}
</script>

Link for popup:
<a href="/games/pool.php" onclick="return popitup(this.href, 500, 400)">3D Pool Deluxe</a>

Thanks
Shawn

and props to glenngv for providing the origonal coding

rm-f
10-20-2005, 04:37 PM
I need is to find out how to center the popup no mater of the size of the popup

Center to what? Room, earth, universe?

antimedia
10-20-2005, 05:50 PM
Well I thought I was pretty explanitory but in case you are misinformed. You see there is this monitor here and I was discussing on the forums how to center a popup window (*hence the title of the post) How to center a popup window? :)

If I am using the examples of top=50, left=200 and described that I want it to not use width and height but to center the popup on the CENTER of the screen. I would hope someone would understand.

I do apologize that for some twisted reason you might of concluded I was discussing a popup window in a center of a room or a javascript popup window in the center of the universe...bah

If anyone knows the answer to my origonal post it would be appreciated
Thanks
Shawn

Nischumacher
10-20-2005, 06:03 PM
function popitup(url,newH,newW)
{ var left = (screen.width-newW)/2;
var top = (screen.height-newH)/2;
var newW = w + 100;
var newH = h + 100;
myWindow = window.open(url, 'name', 'width='+newW+',height='+newH+',left='+left+',top='+top);
myWindow.resizeTo(newW, newH);
myWindow.moveTo(left, top);
myWindow.focus();
}

hope this works...

- NS 666
.net DEVILoper

rm-f
10-20-2005, 06:13 PM
antimedia

For your information: you can center popupwindow to: monitor screen, parent window, a frame or anything else. As mind reading has not been developed yet, you should be more specific.


That deserves a screenshot and post someplace so we can all laugh at you...I already showed mine coworkers your post, we really enjoyed the one.

Nischumacher
10-20-2005, 06:47 PM
oops... i think i made a mistake...
the variables left and top should be assigned values after newH and newW are altered to accomodate for the border...



function popitup(url,newW,newH)
{
var newW = w + 100;
var newH = h + 100;
var left = (screen.width-newW)/2;
var top = (screen.height-newH)/2;
var newwindow = window.open(url, 'name', 'width='+newW+',height='+newH+',left='+left+',top='+top);
newwindow.resizeTo(newW, newH);

//this line will move the popup to the center of... NOT THE UNIVERSE...
newwindow.moveTo(left, top);

newwindow.focus();
return false;
}


now... it seems perfect... :thumbsup:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum