jQueryプラグインまたはストレートJavaScriptを使用してブラウザーのサイズを検出する方法はありますか?
結果が「ライブ」であることが望ましいので、幅または高さが変わると、結果も変わります。
jQueryプラグインまたはストレートJavaScriptを使用してブラウザーのサイズを検出する方法はありますか?
結果が「ライブ」であることが望ましいので、幅または高さが変わると、結果も変わります。
JavaScript
function jsUpdateSize(){
    // Get the dimensions of the viewport
    var width = window.innerWidth ||
                document.documentElement.clientWidth ||
                document.body.clientWidth;
    var height = window.innerHeight ||
                 document.documentElement.clientHeight ||
                 document.body.clientHeight;
    document.getElementById('jsWidth').innerHTML = width;  // Display the width
    document.getElementById('jsHeight').innerHTML = height;// Display the height
};
window.onload = jsUpdateSize;       // When the page first loads
window.onresize = jsUpdateSize;     // When the browser changes size
jQuery
function jqUpdateSize(){
    // Get the dimensions of the viewport
    var width = $(window).width();
    var height = $(window).height();
    $('#jqWidth').html(width);      // Display the width
    $('#jqHeight').html(height);    // Display the height
};
$(document).ready(jqUpdateSize);    // When the page first loads
$(window).resize(jqUpdateSize);     // When the browser changes size
編集: IE8以前をサポートするようにJavaScriptコードを更新しました。
あなたが使用することができます
function onresize (){
   var h = $(window).height(), w= $(window).width();
   $('#resultboxid').html('height= ' + h + ' width: ' w);
}
 $(window).resize(onresize ); 
 onresize ();// first time;
html:
<span id=resultboxid></span>
これにより、表示領域が返されます。
document.body.offsetWidth
document.body.offsetHeight
これは常にブラウザのサイズと同じだと思いますか?
幅と高さの変数を好きな場所で使用してください...ブラウザのサイズが変わると、変数の値も変わります。
$(window).resize(function() {
    width = $(this).width());
    height = $(this).height());
});
このような意味ですかwindow.innerHeight; window.innerWidth $(window).height(); $(window).width()
次のようにサイズ変更時にリスナーを追加してみることができます
window.addEventListener('resize',CheckBrowserSize,false);
function CheckBrowserSize() 
{
    var ResX= document.body.offsetHeight;
    var ResY= document.body.offsetWidth;
}