最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin9浏览0评论
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)

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)

Share Improve this question asked Jul 3, 2011 at 4:18 TIMEXTIMEX 273k368 gold badges802 silver badges1.1k bronze badges
Add a ment  | 

2 Answers 2

Reset to default 5

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./blog/java-script/how-open-new-window-popup-center-screen

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论