In mobile web app (specially in Android, various screen densities are provided), we can get screen density with JavaScript using window.devicePixelRatio DOM property.
<!doctype html>
<head>
<title>Mobile-Web-App: Test Javascript</title>
<meta charset="utf-8">
<script>
function myOnLoad(){
var devicePixelRatio = window.devicePixelRatio;
eleRatio = document.getElementById("ratio");
eleRatio.innerHTML = devicePixelRatio;
}
window.onload = myOnLoad;
</script>
</head>
<body>
<h1>Mobile-Web-App: detect device pixel ratio</h1>
devicePixelRatio: <b id="ratio"></b>
</body>
</html>
No comments:
Post a Comment