2016-12-14 159 views
1

我正在使用此腳本打開並居中具有特定大小的彈出窗口。它按預期工作,Mac OS 10.9.5的Safari 9.0.1版除外,其中窗口以全尺寸打開。 它適用於Mac上的所有其他瀏覽器。彈出窗口不保留Safari中的寬度/高度尺寸

任何想法爲什麼指定的窗口大小不適用於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> 

回答

0

經過大量的調查,似乎這個問題只發生在這個特定的MacBook上。這不是一個普遍的問題,所以我現在要關閉這個topis。

0

嘗試使用這些爲寬/高爲這個JavaScript支持所有瀏覽器:

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

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

這可能是因爲這個使用body.clientHeight /體.clientWidth,但不是100%確定。
希望這有助於!

+1

謝謝,但它沒有工作,對不起。 – Meek

+0

啊,這是一個無賴,不能真正幫助你進一步因爲我沒有一個mac和Safari瀏覽器不真正在Windows上工作 –