如何使用JavaScript检测屏幕DPI [英] How to detect the screen DPI using JavaScript

查看:1415
本文介绍了如何使用JavaScript检测屏幕DPI的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我到目前为止找到的唯一方法是使用 height 获取测试 div 元素的offsetWidth,offsetHeight和宽度一英寸:
http: //www.infobyip.com/detectmonitordpi.php

The only way I found till now, is getting the offsetWidth, offsetHeight of a test div element with height and width of one inch: http://www.infobyip.com/detectmonitordpi.php

有没有办法通过JavaScript检测屏幕DPI?

Is there a way to detect the screen DPI via JavaScript instead?

谢谢,

Atara。

推荐答案

<div id='testdiv' style='height: 1in; left: -100%; position: absolute; top: -100%; width: 1in;'></div>
<script type='text/javascript'>
    dpi_x = document.getElementById('testdiv').offsetWidth;
    dpi_y = document.getElementById('testdiv').offsetHeight;
</script>

然后你可以使用JQuery发送 dpi_x dpi_y 这到你的服务器

Then you can use JQuery to send dpi_x and dpi_y this to to your server

http://jsfiddle.net/sxfv3/

这篇关于如何使用JavaScript检测屏幕DPI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆