擷取浏覽器視窗的大小:
function getInfo(){
var s = "";
s += "網頁可見區域寬:" + document.body.clientWidth;
s += "
網頁可見區域高:"+ document.body.clientHeight;
s += "
網頁可見區域寬:"+ document.body.offsetWidth +" (包括邊線和滾動條)";
s += "
網頁可見區域高:"+ document.body.offsetHeight +" (包括邊線)";
s += "
網頁正文全文寬:"+ document.body.scrollWidth;
s += "
網頁正文部分上:"+ window.screenTop;
s += "
網頁正文部分左:"+ window.screenLeft;
s += "
螢幕分辨率的高:"+ window.screen.height;
s += "
螢幕分辨率的寬:"+ window.screen.width;
s += "
螢幕可用工作區高度:"+ window.screen.availHeight;
s += "
螢幕可用工作區寬度:"+ window.screen.availWidth;
s += "
你的螢幕設定是 "+ window.screen.colorDepth +" 位彩色";
s += "
你的螢幕設定 "+ window.screen.deviceXDPI +" 像素/英寸";
s += "
網頁真實寬:" + document.documentElement.scrollWidth;
s += "
網頁真實高:"+ document.documentElement.scrollHeight;
document.write(s);
}
簡單示例:
判斷分辨率,假如分辨率低于1024則去掉背景圖:
if(window.screen.width<1024){
//alert('成立');
document.getElementById('main').style.background='none';
}else{
}