Open popup windows in the center of the screen.

This code will automatically open a popup window in the center of the user's screen, regarless of the resolution.
JavaScript


//default value is available screen dimensions can not be returned
var w = 640, h = 480;

//retrieve available screen dimensions
if (document.all || document.layers) {
   w = screen.availWidth;
   h = screen.availHeight;
}

//set the popup windows width and height
var popW = 350, popH = 400;

//calculate the left and top positions based on the screen width & height, along with the popup window width & height
var leftPos = (w-popW)/2, topPos = (h-popH)/2;

//open the popup window
window.open(document.forms[0].dbURL.value + "/MyCats?OpenForm", "","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=" + popW + ',height=' + popH + ',top=' + topPos + ',left=' + leftPos);

Posted by fbrefere001 on Friday February 6, 2004