Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@triceam
Created May 1, 2012 18:31
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save triceam/2570291 to your computer and use it in GitHub Desktop.
Save triceam/2570291 to your computer and use it in GitHub Desktop.
Form factor detection in JavaScript (tablet vs phone) w/ jQuery
var _w = Math.max( $(window).width(), $(window).height() );
var _h = Math.min( $(window).width(), $(window).height() );
// assume tablet view based upon display resolution
var tabletView = (_w >= 1000 && _h >= 600);
if ( tabletView ) {
//Setup the tablet form factor via JS
}
else {
//Setup the phone form factor via JS
}
@MatthewHallCom
Copy link

Works great with iPhones and iPads, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment