本文目录一览:
怎样用js判断手机屏幕的分辨率,根据不同的分辨率给定不一样的事件.急求!!!
用screen.width可以判断屏幕分辨率的宽度,用screen.height可以判断屏幕分辨率的高度!
if (screen.width = 1440){
//这里执行事件1
}else if (screen.width = 1366){
//这里执行事件2
}else if (screen.width = 800){
//这里执行事件3
}else {
//这里执行事件4
}
js怎么判断屏幕分辨率
script language="JavaScript"
!-- Begin
function redirectPage() {
var w=screen.width;
var h=screen.height;
alert("经系统检测,你的屏幕分辨率为 " + w+"*"+ h );
}
// End --
/script
求问Javascript如何获取屏幕的分辨率(PPI/DPI)?
获取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:1in;height:1in;position:absolute;left:0px;top:0px;z-index:99;visibility: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());
}