Created
November 16, 2010 15:55
-
-
Save ahmednuaman/701964 to your computer and use it in GitHub Desktop.
A simple little script to check for a touch enabled device
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var el = document.createElement( 'div' ); | |
el.setAttribute( 'ontouchstart', 'return;' ); | |
if ( typeof el.ontouchstart == 'function' ) | |
{ | |
// yay a touch device! | |
} |
Interesting... Must've been the sleepless nights of the project that caused me to come up with this special way!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Wouldn't
if(document.body.ontouchstart) { /* yay touch device */ }
work just as well (and not make you create things/initialize vars/set attributes)?