Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I center a popup window for all resolutions

Opening and closing a window

How do I center a popup window for all resolutions

by  adrikev  Posted    (Edited  )
As you already know, everyone has a different graphics resolution on their PC. So how do you center a pop-up window for all resolutions. It is easier than you think.

Lets say you want to open a window that has a size of 200h x 150w. By taking half of the height and width (100 and 75 respectively) you can pinpoint the center of the window. Then with a little math you can center the window. Here is how it is done
[color red]
Code:
<SCRIPT LANGUAGE="JavaScript">
function MyPopUpWin() {
var iMyWidth;
var iMyHeight;
//half the screen width minus half the new window width (plus 5 pixel borders).
iMyWidth = (window.screen.width/2) - (75 + 10);
//half the screen height minus half the new window height (plus title and status bars).
iMyHeight = (window.screen.height/2) - (100 + 50);
//Open the window.
var win2 = window.open("filename.htm","Window2","status=no,height=200,width=150,resizable=yes,left=" + iMyWidth + ",top=" + iMyHeight + ",screenX=" + iMyWidth + ",screenY=" + iMyHeight + ",toolbar=no,menubar=no,scrollbars=no,location=no,directories=no");
win2.focus();
}
</SCRIPT>
[/color]
To call this function in HTML use this:
[color red]
Code:
<A HREF="javascript:MyPopUpWin()">This is the link</a>
[/color]
It's that simple.
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top