window.open 居中显示

openwindow = function (data) {
    var url = data.url;                                          //转向网页的地址;  
    var name = data.title || '选择要添加的页面';                  //网页名称,可为空;  
    var iWidth = data.width || '860';                           //弹出窗口的宽度;  
    var iHeight = data.height || window.innerHeight * 0.8;      //弹出窗口的高度;
    var iTop = (window.screen.height - 30 - iHeight) / 2;       //获得窗口的垂直位置;  
    var iLeft = (window.screen.width - 10 - iWidth) / 2;        //获得窗口的水平位置;  
    window.open(url, name, 'height=' + iHeight + ',,innerHeight=' + iHeight + ',width=' + iWidth + ',innerWidth=' + iWidth + ',top=' + iTop + ',left=' + iLeft + ',toolbar=no,menubar=no,scrollbars=auto,resizeable=no,location=no,status=no');
}

// 调用
openwindow({url: 'http://www.vars.cc'});

猜你喜欢

转载自blog.csdn.net/pintu274111451/article/details/80111454
今日推荐