Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/428.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用我已有的代码将javascript弹出窗口居中_Javascript_Popup_Window_Center - Fatal编程技术网

如何使用我已有的代码将javascript弹出窗口居中

如何使用我已有的代码将javascript弹出窗口居中,javascript,popup,window,center,Javascript,Popup,Window,Center,我需要能够中心弹出窗口出现。我知道这已经被问了很多次了,但我找不到一个有效的。请帮忙 jQuery(document).ready(function (jQuery) { jQuery('.open-window').click(function () { var NWin = window.open(jQuery(this).prop('href'), '', 'scrollbars=1,height=400,width=400');

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

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

我想这就是你想要的

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

我想这就是你想要的

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

谢谢!工作得很好!非常感谢。工作得很好!