Anatoly Lubarsky

Logo
MSSQL, .NET, Design. Life and Music

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.


Related Posts:

Monday, January 08, 2007 12:40 AM

If your feedback doesn't appear right away, please be patient as it may take a few minutes to publish.

Post a Comment

Protected by CAPTCHAEnter the code you see
Name (*)  
E-mail (*)  
Url
Remember

Comment (*)