How to center a popup window?

后端 未结 3 1695
无人及你
无人及你 2020-12-30 08:42

Center a popup window on screen? these don\'t work in Chrome w/ multimonitor. The \"screen\" seems to refer to the entire desktop, not just the current window. I want to cen

3条回答
  •  旧时难觅i
    2020-12-30 09:12

    Here's a demo (should load Google):

    function popupwindow(url, title, w, h) {
      wLeft = window.screenLeft ? window.screenLeft : window.screenX;
      wTop = window.screenTop ? window.screenTop : window.screenY;
    
      var left = wLeft + (window.innerWidth / 2) - (w / 2);
      var top = wTop + (window.innerHeight / 2) - (h / 2);
      return window.open(url, title, 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=' + w + ', height=' + h + ', top=' + top + ', left=' + left);
    }

提交回复
热议问题