Javascript: Open Pop-Up at Center of Client Window
In javascript - window.open opens a pop-up that by default opens at random location of the window. Below is a javascript function that will open a pop-up in the center of the client window. Hope it may save many additional lines of javascript code.
function windowOpener(windowHeight, windowWidth, windowName, windowUri)
{
    var centerWidth = (window.screen.width - windowWidth) / 2;
    var centerHeight = (window.screen.height - windowHeight) / 2;
    newWindow = window.open(windowUri, windowName, 'resizable=0,width=' + windowWidth + 
        ',height=' + windowHeight + 
        ',left=' + centerWidth + 
        ',top=' + centerHeight);
    newWindow.focus();
    return newWindow.name;
}
Please notice parameters that are passed to window.open.
Monday, January 8, 2007 12:40 AM
 
                    
