Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

#880 - Simple fix to improve the detection for real touch based devices #920

Closed
wants to merge 1 commit into from

3 participants

@tvpmb
  • fixes the false positive seen on Windows 8 (Chrome, FF)
@tvpmb tvpmb Simple fix to improve the detection for real touch based devices
- fixes the false positive seen on Windows 8 (Chrome, FF)
048976e
@roblarsen

I'm not sure what you're testing on, but that produces two different results on a touch enabled Win8 laptop.

in FF latest

>>> typeof window.Touch

"object"

in Chrome latest

>typeof window.Touch
"function"

the original test ("ontouchstart" in window) is true on both

@tvpmb

Yeah, I don't have that type of device to test against...let me think about this some more.

@tvpmb

@roblarsen Just curious, what's the make/model of that device? One of the guys here has a surface pro, trying to find something to test against.

@roblarsen

A Lenovo Yoga 13

@stucox
Owner

Ok, to clairfy once again, Modernizr.touch is not intended to detect touch devices. It detects support for the Touch Events API, which I think this test does reliably... the exceptions seen on #880 seem to be cases whereby the APIs are enabled unexpectedly.

We don't believe it's currently possible to detect touch-capable devices reliably... see this thread: #548.

So I'm afraid I'm going to kill this. Let's carry on the discussion about why we're getting false-positives in Win 8 on #880.

@stucox stucox closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 3, 2013
  1. @tvpmb

    Simple fix to improve the detection for real touch based devices

    tvpmb authored
    - fixes the false positive seen on Windows 8 (Chrome, FF)
This page is out of date. Refresh to see the latest.
Showing with 2 additions and 1 deletion.
  1. +2 −1  feature-detects/touchevents.js
View
3  feature-detects/touchevents.js
@@ -33,7 +33,8 @@ Chrome (desktop) used to lie about its support on this, but that has since been
define(['Modernizr', 'prefixes', 'testStyles'], function( Modernizr, prefixes, testStyles ) {
Modernizr.addTest('touchevents', function() {
var bool;
- if(('ontouchstart' in window) || window.DocumentTouch && document instanceof DocumentTouch) {
+
+ if((typeof window.Touch === "object") || window.DocumentTouch && document instanceof DocumentTouch) {
bool = true;
} else {
var query = ['@media (',prefixes.join('touch-enabled),('),'heartz',')','{#modernizr{top:9px;position:absolute}}'].join('');
Something went wrong with that request. Please try again.