1

私は現在、次の条件を使用していますが、ブラウザー間で機能していないか、まったく機能していません。

if (typeof (window.innerHeight) == 'number') {
    //Non-IE:
    //Perform operation using window.innerWidth/Height
} else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
    //IE 6+ in 'standards compliant mode'
    //Perform operation using document.documentElement.clientWidth/Height
} else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
    //IE 4 compatible
    //Perform operation using document.body.clientWidth/Height
}

条件が1つか2つ欠けていると思います。おそらく、考慮していない別の一般的な表現があります。

これを完了するには何を追加する必要がありますか?

4

2 に答える 2

1

ページにjQueryを含め、とを使用$(window).width()$(window).height()ます。

于 2010-11-08T18:34:36.087 に答える
0

ロジック全体を関数にラップする方がよいので、次のように言うだけで済みます。getWindowHeight()

// cross browser window height
function getWindowHeight() {
  return window.innerHeight || 
         (document.documentElement && document.documentElement.clientHeight) || 
         (document.body && document.body.clientHeight);
}

テスト済み:IE5.5 +、FF 2 +、Chrome、Opera

ただし、さらに堅牢なアプローチについては、関連するcomp.lang.javascript FAQエントリにアクセスしてください
。ウィンドウのサイズを確認するにはどうすればよいですか?

于 2010-11-08T18:40:56.820 に答える