Skip to content

Instantly share code, notes, and snippets.

@Spaxe
Created February 8, 2012 12:16
Show Gist options
  • Select an option

  • Save Spaxe/1768815 to your computer and use it in GitHub Desktop.

Select an option

Save Spaxe/1768815 to your computer and use it in GitHub Desktop.
Detecting Mobile devices with Javascript
function TouchScreenAdapt()
{
if (typeof TouchEvent != "undefined")
{
$('body').removeClass('mouse').addClass('touch');
}
}
@cobbweb
Copy link
Copy Markdown

cobbweb commented Feb 8, 2012

I just got stung by this, Chrome v17 went stable last night which includes TouchEvent even if you don't have a touch device. Use "ontouchstart" in document.documentElement" instead :)

@Spaxe
Copy link
Copy Markdown
Author

Spaxe commented Feb 8, 2012

Thanks Andrew!

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