2016-12-14 6 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のための幅/高さのためにこれらを使用してみてくださいは、すべてのブラウザをサポートしています。これはbody.clientHeight /体を使用しているため、

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

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

それはあるかもしれません.clientWidth、確かに100%ではありません。
これが役立つことを願っています!

+1

ありがとうございますが、うまくいきませんでした。申し訳ありません。 – Meek

+0

ああ、それはバマーです、本当に私はMacとサファリを持っていないため、さらにあなたを助けることはできません本当に窓で動作しません –

関連する問題