PDA

View Full Version : Centering in browser window


Gary Williams
11-14-2002, 12:47 PM
Hi All,

Can someone please upload the code snippet that centers a page/popup window in the middle of the screen irrespective of browser type/version or screen resolution.

I saw on the forum a couple of days ago but have lost the copy I made and now can't find it again - Doh!!

Thanks

Gary

boggly
11-14-2002, 01:07 PM
Yeah, it would be something like this:

function openWin(url, w, h)
{
var left = 0;
var top = 0;

if (window.screen)
{
left = Math.floor((screen.availWidth - w) / 2 );
top = Math.floor((screen.availHeight - h) / 2 );
}

var settings = 'width=' + w + ',height=' + h + ',top=' + top + ',left=' + left + ',screenX=' + left + ',screenY=' + top;

window.open(url,"win",settings);
}

Regards,
boggly

Gary Williams
11-14-2002, 01:12 PM
Thanks Boggly,

Any idea of the tweeks needed to make the script work in both NN and IE?

Thanks

Gary

boggly
11-14-2002, 01:20 PM
I think it should.

-boggly