0

On my Windows 8 desktop PC (non-touchscreen), Firefox 26 incorrectly reports itself as a touchscreen device while other browsers like Chrome & IE don't?

Using the following different JavaScript snippets, Firefox always returns true and Chrome always false.

jQuery.support.touch

Of this code from James https://stackoverflow.com/a/4819886/498187

function is_touch_device() {
  return 'ontouchstart' in window // works on most browsers 
      || 'onmsgesturechange' in window; // works on ie10
};

My question is, is there a better way to check for touchscreen devices, one that Firefox will understand?

Community
  • 1
  • 1
Owen
  • 760
  • 1
  • 7
  • 25

2 Answers2

2

Your code should work fine on firefox too in most cases, 'ontouchstart' in window should evaluate to false in firefox too, unless you have set the preference "dom.w3c_touch_events.enabled" to "1".

Type about:config in Firefox's address bar and search for this property. If it is 1 just make it 0 and then the expression 'ontouchstart' in window should evaluate to false (maybe you 'll need to restart firefox).

It isn't necessary that you set this option to '1' yourself in the past. If you have ever used Firefox's developer tools to emulate touch events, that must have done it. But the average Firefox user wouldn't have done so so I wouldn't worry about it :)

There's a relevant issue raised on bugzilla.

gerry
  • 801
  • 1
  • 9
  • 14
0
if ('ontouchstart' in window
    || navigator.maxTouchPoints > 0
    || navigator.msMaxTouchPoints > 0
) {
      /* Browser with either Touch Events of Pointer Events
          running on touch-capable device. */
}
ChrisF
  • 180
  • 8