TIMEX TIMEX - 4 months ago 6
HTML Question

After I launch a popup window, how do I move it to the center of the page?

popup = window.open(thelink,'Facebook Share','resizable=1,status=0,location=0,
width=500,height=300');


I want to move this window all the way into the center (vertically and horizontally)

Answer

Owalla,

I got something like this plain javascript straight from google search, we can do it in jquery in much simpler way but try someting like this

var myWindow;

function openCenteredWindow(url) {
    var width = 400;
    var height = 300;
    var left = parseInt((screen.availWidth/2) - (width/2));
    var top = parseInt((screen.availHeight/2) - (height/2));
    var windowFeatures = "width=" + width + ",height=" + height + ",status,resizable,left=" + left + ",top=" + top + "screenX=" + left + ",screenY=" + top;
    myWindow = window.open(url, "subWind", windowFeatures);
}
Comments