设置窗口弹出坐标

时间:2012-04-30 07:30:34

标签: javascript jquery jquery-ui jquery-ui-dialog

我正在使用这样的JQuery UI Dialog;

 $(function () {
        var dlg = $("#dialog").dialog({
            draggable: true,
            resizable: false,
            width: 950,
            height: 480,
            autoOpen: false,
            modal: true,
            minHeight: 30,
            minwidth: 30,
            title: 'test'
        });
    });

窗口:

    function PopupUrl(url, name, width, height) {
        var features = "location=1, status=1, scrollbars=1, width=" + width + ", height=" + height + '"';
        window.open(url, name, features);
    }

Dialog打开了页面的中心,但弹出窗口显示不同的坐标。我想要重叠。怎么做?

1 个答案:

答案 0 :(得分:2)

只需将计算出的顶部和左侧添加到功能列表中,弹出窗口将位于屏幕中央:

function PopupUrl(url, name, width, height) {
    var top = parseInt((screen.availHeight / 2) - (height / 2));
    var left = parseInt((screen.availWidth / 2) - (width / 2));
    var features = "location=1, status=1, scrollbars=1, width=" + width + ", height=" + height + ", top=" + top + ", left=" + left;
    window.open(url, name, features);
}