【问题标题】:How to center a javascript popup window with the code I already have如何使用我已经拥有的代码使 javascript 弹出窗口居中
【发布时间】:2015-11-09 20:17:50
【问题描述】:

我需要能够使出现的弹出窗口居中。我知道这已被问过很多次,但我找不到一个有效的。请帮忙!

jQuery(document).ready(function (jQuery) {
       jQuery('.open-window').click(function () {
            var NWin = window.open(jQuery(this).prop('href'), '', 'scrollbars=1,height=400,width=400');
                  if (window.focus) {
                      NWin.focus();
                  }
                  return false;
      });
});

【问题讨论】:

    标签: javascript popup window center


    【解决方案1】:

    我想这就是你所追求的

    jQuery(document).ready(function (jQuery) {
        var screenWidth = (screen.width-400)/2,
            screenHeight = (screen.height-400)/2;
    
    jQuery('.open-window').click(function () {
        var NWin = window.open(jQuery(this).prop('href'), '', "'scrollbars=1, height=400, width=400, top="+screenHeight+", left="+screenWidth+"'");
    
        if (window.focus) {
            NWin.focus();
        }
        return false;
        });
    });
    

    http://jsbin.com/cesitun/edit?html,js,console,output

    【讨论】:

    • 谢谢!完美运行!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-04
    • 2016-02-12
    • 2013-05-02
    相关资源
    最近更新 更多