【问题标题】:Popup window not keeping width/height dimensions in Safari弹出窗口未在 Safari 中保持宽度/高度尺寸
【发布时间】:2016-12-21 17:05:39
【问题描述】:

我正在使用这个脚本来打开一个特定大小的弹出窗口并将其居中。它按预期工作,但在 Mac OS 10.9.5 上的 Safari 版本 9.0.1 中,窗口以全尺寸打开。 它适用于 Mac 上的所有其他浏览器。

任何想法为什么指定的窗口大小在 Safari 中不起作用?

function PopupCenter(url, title, w, h) {
  var dualScreenLeft = window.screenLeft != undefined ? window.screenLeft : screen.left;
  var dualScreenTop = window.screenTop != undefined ? window.screenTop : screen.top;
  var width = window.innerWidth ? window.innerWidth : document.documentElement.clientWidth ? document.documentElement.clientWidth : screen.width;
  var height = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight ? document.documentElement.clientHeight : screen.height;
  var left = ((width / 2) - (w / 2)) + dualScreenLeft;
  var top = ((height / 2) - (h / 2)) + dualScreenTop;
  var newWindow = window.open(url, title, 'toolbar=no, location=no, directories=no, status=no, menubar=no,scrollbars=yes,resizable=yes, width=' + w + ', height=' + h + ', top=' + top + ', left=' + left);

  // Puts focus on the newWindow
  if (window.focus) {
    newWindow.focus();
  }
}

用法:

<a href="#" onclick="PopupCenter('http://www.google.com','Window title','500','600'); return false;">Click</a>

【问题讨论】:

    标签: javascript safari popup


    【解决方案1】:

    尝试使用这些作为此 javascript 支持所有浏览器的宽度/高度:

    var width = window.innerWidth
    || document.documentElement.clientWidth
    || document.body.clientWidth;
    
    var heigth = window.innerHeight
    || document.documentElement.clientHeight
    || document.body.clientHeight; 
    

    这可能是因为这使用了 body.clientHeight/body.clientWidth,但不是 100% 确定。
    希望这会有所帮助!

    【讨论】:

    • 啊,这真是太糟糕了,因为我没有 Mac,而且 safari 不能在 Windows 上真正运行,所以无法进一步帮助你
    【解决方案2】:

    经过大量调查,这个问题似乎只发生在这台特定的 MacBook 上。这不是一般性问题,所以我现在将关闭此话题。

    【讨论】:

      猜你喜欢
      • 2011-10-20
      • 1970-01-01
      • 1970-01-01
      • 2012-11-29
      • 1970-01-01
      • 2011-11-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多