Ali Chambers wrote:
Hi,
I'd like to open a popup window in the middle of the current browser
window. The browser window could be any size and height (as resized by
the user). The popup should be in the center of x and y. Can anyone
provide the JS code to do this:
pop-up width = 100
pop-up height = 100
Thanks,
Alex
Here it is:
function CenterWndLeft(wnd_width) {
return screen.width/2 - wnd_width/2;
}
function CenterWndTop(wnd_height) {
return screen.height/2 - wnd_height/2;
}
function CenterWnd(wnd, wnd_width, wnd_height) {
wnd.resizeTo(wnd_width,wnd_height);
wndLeft = CenterWndLeft(wnd_width);
wndTop = CenterWndTop(wnd_height);
wnd.moveTo(wndLeft,wndTop);
}
So you use function CenterWnd, passing the window, desired width and desited height, and the func
resizes/relocates the window.
Or you can use directly CenterWndLeft and CenterWndTop functions to get coordinates of top left
corner of your new pop-up window.
Hope it helps,
Andrey