码迷,mamicode.com
首页 > Web开发 > 详细

网页 js 获取DPI pxTomm

时间:2015-06-30 08:54:47      阅读:181      评论:0      收藏:0      [点我收藏+]

标签:

//获取DPI
function js_getDPI() {
    var arrDPI = new Array();
    if ( window.screen.deviceXDPI != undefined ) {
        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;
}
 var mm = pxValue/dpi*2.54*10;//dpi为上面获取的,自己对应XY轴

 

网页 js 获取DPI pxTomm

标签:

原文地址:http://www.cnblogs.com/houkaihua/p/4609363.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!