开发者

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

开发者 https://www.devze.com 2023-03-16 19:09 出处:网络
popup = window.open(thelink,\'Facebook Share\',\'resizable=1,status=0,location=0, width=500,height=300\');
popup = window.open(thelink,'Facebook Share','resizable=1,status=0,location=0,
width=500,height=300');

I want to move this window all 开发者_如何学Cthe way into the center (vertically and horizontally)


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);
}


Try this script

function PopupCenter(pageURL, title,w,h) {
var left = (screen.width/2)-(w/2);
var top = (screen.height/2)-(h/2);
var targetWin = window.open (pageURL, title, 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width='+w+', height='+h+', top='+top+', left='+left);
} 

Link here : http://www.nigraphic.com/blog/java-script/how-open-new-window-popup-center-screen

0

精彩评论

暂无评论...
验证码 换一张
取 消