js获取分辨率和缩放页面的方法

JavaScript012

js获取分辨率和缩放页面的方法,第1张

var screen = window.screen//获取分辨率

screen.width;//获取分辨率的宽度

screen.height;//获取分辨率的高度

//页面缩放比例设置方法

document.getElementsByTagName('body')[0].style.zoom=0.67//该方法将页面设置比例调整为67%

<script language="JavaScript">  

<!-- Begin  

function redirectPage() {  

var w=screen.width

var h=screen.height

alert("经系统检测,你的屏幕分辨率为 " + w+"*"+ h )  

}  

// End -->  

</script>

获取PPI:

function js_getDPI() {

var arrDPI = new Array

if (window.screen.deviceXDPI) {

arrDPI[0] = window.screen.deviceXDPI

arrDPI[1] = window.screen.deviceYDPI

}

else {

var tmpNode = document.createElement("DIV")

tmpNode.style.cssText = "width:1inheight:1inposition:absoluteleft:0pxtop:0pxz-index:99visibility:hidden"

document.body.appendChild(tmpNode)

arrDPI[0] = parseInt(tmpNode.offsetWidth)

arrDPI[1] = parseInt(tmpNode.offsetHeight)

tmpNode.parentNode.removeChild(tmpNode)

}

return arrDPI

}

window.onload=function(){

alert("当前屏幕PPI "+js_getDPI())

}