Pop-up in window center

A

Ali Chambers

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
 
A

Andrey

Ali said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top