2

With the number of new touch enabled full size PC's, what are some efficient ways to determine if the user is browsing with one of these touch enabled devices? Preferably a method that can detect any touch enabled device (Android, iPad, Windows RT, Windows 8)?

Kirill Fuchs
  • 13,446
  • 4
  • 42
  • 72
  • 1
    Check this out [Link](http://stackoverflow.com/questions/4817029/whats-the-best-way-to-detect-a-touch-screen-device-using-javascript), maybe it will help. – Eric Goncalves Nov 26 '12 at 22:00

3 Answers3

3

Using javascript, this is pretty widespread:

if('ontouchstart' in document) {
    // touch events detected
}

There are new touch devices coming out every week, so it’s probably safer to use the latest Modernizr if you want the best detection though.

David Hellsing
  • 106,495
  • 44
  • 176
  • 212
2

I have used the following code in a previous project:

var is_touch = 'ontouchstart' in document.documentElement;

if(is_touch){
    // Touch capable.

}
ajtrichards
  • 29,723
  • 13
  • 94
  • 101
1

Modernizr project has way of checking for touch capabilities but notes that there is not a completely reliable way to check as some desktop browsers lie about their support and some mobile browsers don't support the touch events.

Test results from a wide range of browsers are here.

mnorrish
  • 479
  • 5
  • 11