JavaScript centered popup window
August 15th, 2007 | Author: ChipToday’s tutorial is about JavaScript and how to pop up a window in the center of the screen and focus on it. The trick is easy and the containing function is small. Here it is the JS code:
function window_popup(content, x, y, title) {
var thisWindow;
thisWindow = window.open(content,title,"width="+x+",height="+y+",scrollbars=auto,screenX=0,screenY=0,toolbar=no,location=no,menubar=no");
thisWindow.moveTo((screen.width-x)/2,(screen.height-y)/3);
thisWindow.window.focus();
}
And here is the caller:
<a href="#" onclick="window_popup('mypage.html', 400, 300, 'mypage')">Open My Page</a>
Remember to quote the page name and title, otherwise the script will generate an error. Popup window attributes can be changed in the second line of the function
scrollbars=auto,screenX=0,screenY=0,toolbar=no,location=no,menubar=no
depending on what is the role of the window.

Hi, how cross-browser compatible is this solution? And does it put it in the centre of the window, regardless of vertical scroll position?
I’ve struggled a bit with this, and thought I might just use a solution like lightwindow.
Cheers