javascript - 设置弹出窗口坐标

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

我正在使用这样的 JQuery UI 对话框;

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

对话框已在页面中心打开,但弹出窗口显示不同的坐标。我想重叠。如何做到这一点?

最佳答案

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

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

关于javascript - 设置弹出窗口坐标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10380015/

相关文章:

jQuery CSS 背景图像声明?

javascript - jquery - ajax 请求不工作

javascript - 通过lambda函数向SQS发送消息时如何插入

javascript - 我需要包含哪些 js 文件才能使用 ExtJs 日历?

jquery getJSON 没有响应,但直接访问有响应

javascript - 如何删除用户使用 JavaScript 输入的文本输入

javascript - 在提交调试之前显示表单值

javascript - 在javascript中选择区域/矩形

javascript - 通过 chrome 扩展更改输入文本

javascript - 删除除第一个 child 之外的所有子元素?