Skip to content

Instantly share code, notes, and snippets.

@kazu69
Created April 3, 2012 00:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kazu69/2288426 to your computer and use it in GitHub Desktop.
Save kazu69/2288426 to your computer and use it in GitHub Desktop.
device check
function iOS_hasRetinaDisplay()
{
return window.devicePixelRatio > 1;
}
//UAでデバイスのチェック
function iOS_initPage()
{
if(navigator.standalone) iOS_createWebappLinks();
// iOS class
var ua = navigator.userAgent;
if(iOS_isiOSdevice())
{
var html = document.documentElement;
// set the iOS class on <html>
var classes = html.className.split(" ");
if(classes.indexOf("iOS") == -1) classes.push("iOS");
if(iOS_hasRetinaDisplay() && classes.indexOf("retina") == -1) classes.push("retina");
html.className = classes.join(" ");
// Device
if(ua.indexOf("iPhone") > -1) html.setAttribute("device", "iPhone");
else if(ua.indexOf("iPod") > -1) html.setAttribute("device", "iPod");
else if(ua.indexOf("iPad") > -1) html.setAttribute("device", "iPad");
// Device Family
if(ua.indexOf("iPhone") > -1 || ua.indexOf("iPod") > -1) html.setAttribute("deviceFamily", "iPhone_iPod");
else if(ua.indexOf("iPad") > -1) html.setAttribute("deviceFamily", "iPad");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment