rWidth.textContent = screen.width
rHeight.textContent = screen.height
aWidth.textContent = screen.availWidth
aHeight.textContent = screen.availHeight
pWidth.textContent = innerWidth
pHeight.textContent = innerHeight
dWidth.textContent = document.body.clientWidth
dHeight.textContent = document.body.clientHeight
//doWidth.textContent = document.body.offsetWidth
//doHeight.textContent = document.body.offsetHeight
//sWidth.textContent = document.body.scrollWidth
//sHeight.textContent = document.body.scrollHeight
pAspect.textContent = devicePixelRatio
userA.textContent = navigator.userAgent
function isRetina(){
// source https://en.wikipedia.org/wiki/Retina_Display#Models
var knownRetinaResolutions = [[272,340], [312,390], [960,640], [1136,640 ], [1334,750 ], [1920,1080], [2048,1536], [2732,2048], [2304,1440], [2560,1600], [2880,1800], [4096,2304], [5120,2880]];
var knownPhones = [[960,640], [1136,640 ], [1334,750 ], [1920,1080]];
var knownPads = [[2048,1536], [2732,2048]];
var knownBooks = [[2304,1440], [2560,1600], [2880,1800], [4096,2304], [5120,2880]];
var hasRetinaRes = knownRetinaResolutions.some(known => known[0] === screen.width && known[1] === screen.height);
var isACrapple = /(iPhone|iPad|iPod|Mac OS X|MacPPC|MacIntel|Mac_PowerPC|Macintosh)/.test(navigator.userAgent);
var hasPhoneRes = knownPhones.some(known => known[0] === screen.width && known[1] === screen.height);
var isPhone = /iPhone/.test(navigator.userAgent);
var hasPadRes = knownPads.some(known => known[0] === screen.width && known[1] === screen.height);
var isPad = /iPad/.test(navigator.userAgent);
var hasBookRes = knownBooks.some(known => known[0] === screen.width && known[1] === screen.height);
var isBook = /Mac OS X|MacPPC|MacIntel|Mac_PowerPC|Macintosh/.test(navigator.userAgent);
var isAgentMatchingRes = (isBook && hasBookRes && !isPad && !isPhone) ||
(isPad && hasPadRes && !isBook && !isPhone) ||
(isPhone && hasPhoneRes && !isBook && !isPad)
return devicePixelRatio >= 2 &&
isACrapple &&
hasRetinaRes &&
isAgentMatchingRes;
}
guess.textContent = isRetina() ? "Yes" : "No";
div, h1, span {
font-family : arial;
}
span {
font-weight : bold
}
<div class="r-display" id="info">
<h1>System info</h1>
<div>Device resolution :
<span id = "rWidth"></span> by <span id = "rHeight"></span> pixels
</div>
<div>Availabe resolution :
<span id = "aWidth"></span> by <span id = "aHeight"></span> pixels
</div>
<div>Page resolution :
<span id = "pWidth"></span> by <span id = "pHeight"> </span> CSS pixels
</div>
<div>Document client res :
<span id = "dWidth"></span> by <span id = "dHeight"> </span> CSS pixels
</div>
<div>Pixel aspect :
<span id = "pAspect"></span>
</div>
<div>User agent :
<span id="userA"></span>
</div>
<h3>Best guess is retina "<span id = "guess"></span>!"</h3>
</div>