以下のような関数を定義する。
var getClientSize = function(){ var client = (function(){ if(!!(window.attachEvent && !window.opera) && document.compatMode == 'CSS1Compat'){ return document.documentElement; } else if(!!(window.attachEvent && !window.opera)){ return document.body; } else{ return document.documentElement; } })(); return {"width" : client.clientWidth , "height" : client.clientHeight}; }
サンプルとして以下のようなコードを実行する。
alert(getClientSize().width);//幅 alert(getClientSize().height);//高さ
ブラウザの表示領域のサイズは意外と知りたい機会があるかもしれない。
ピンバック: Symfoware