How do you center the a pop-up window on the screen after a mouseclick on a button?
| SitePoint Sponsor |
How do you center the a pop-up window on the screen after a mouseclick on a button?
The only way I know is to state the number of pixels from the left and from the top.
i.e.
function openPopup(url_param) {
var popupWin = null;
popupWin = window.open(url_param, 'remote', 'width=400,height=375,resizable=no,menubar=no,toolbar=no,left=200, top=100,scrollbars=yes')
popupWin.opener.name="main";
}
Hope this helps
Saz
The Postfive Website
Postfive Publishing


You might want to check this out
http://tech.irt.org/articles/js128/#2.2
Thank you so much! I really appreciate the help!![]()


So to center a window, you'd use something like:
aDogCode:windowWidth=define Width of new window; windowHeight=define Height of new window; ww=(screen.availWidth-windowWidth)/2; hh=(screen.availHeight-windowHeight)/2; window.open('somepage.html','','width='+windowWidth+',height='+windowHeight+',top='+wh+',left='+ww+',screenY='+wh+',screenX='+ww);![]()
Moderator at www.javascriptcity.com/forums/
I'm a little confused with that last script. As I understand it, this script is designed to compensate for all resolutions and monitor sizes, correct? Well, here's what I didn't understand..
+windowWidth+
Do I type that as is? Is that a variable? I'm sorry, my Javascript is not that good, and I was wondering if you could clear this up for me.
Thanks!


Hey,
Those are just variables I made. What you'd do is fill in the width and height of the new window you want here:
windowWidth=define Width of new window;
windowHeight=define Height of new window;
Anyone know why there's a space here:
,screen X='+ww);
when it should be:
,screenX='+ww);
That's in my post, but it shows up on screen witht he space.
aDog![]()
Moderator at www.javascriptcity.com/forums/
Oh, I get it. Thanks!![]()


You might want to go back to your post and try editing so someone doesn't try using it without noticing the space.Originally posted by Arielladog
Anyone know why there's a space here:
,screen X='+ww);
when it should be:
,screenX='+ww);
That's in my post, but it shows up on screen witht he space.
aDog![]()


I don't see what I could try to edit...
aDog![]()
Moderator at www.javascriptcity.com/forums/
Bookmarks