Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

touch class placed on all browers on windows 8 on a regualr pc with no touch support #880

Closed
woutergovaert opened this Issue · 36 comments

10 participants

@woutergovaert

No description provided.

@stucox
Owner

Could you create a jsFiddle which reproduces this?

Note that Modernizr.touch tests if the browser supports the Touch Events API; not necessarily that there's a touchscreen connected. But still, most PC browsers don't support Touch Events (or at least disable the API when there's no touchscreen) so this sounds odd...

@woutergovaert

Sorry for the late response (I was on holiday).
I've added some screenshots (chrome and firefox have the touch class, ie10 has not)
firefox
firefox
chrome
ie10

@stucox
Owner

It's possible that Firefox and Chrome have enabled the touch APIs by default on Win 8 now... I'll ask around.

In which case, this isn't a false positive.

@fitli65

Hi,

Since today I have the same problem with chrome 26 and firefox 20!
Safari5.1 works well as IE10 does too...
All on a Windows 8 PC

Is there an other way to detect touch screens with modernizr?

@tvpmb

I can also confirm this behavior as well. Using Windows 8, inside a VMWare virtual machine, on MBP.

Seems like the touch API detection isn't enough for what people need to use it for, or there needs to be a better combination of detection for devices that aren't Smartphones/Mobile, but are touch enabled (tablets, ultrabooks, Win8 devices).

@stucox
Owner

@fitli65 Modernizr.touch doesn't detect touchscreens! – just Touch Events API.

But still, I've confirmed with the Chrome guys that they still disable the API when there's no touchscreen on Win 8, so I'm surprised this is true with no touchscreen connected.

Can you let me know what you see here? http://codepen.io/anon/pen/JAsdy

(for some reason the 'pen' and 'full' views of that show different results on my Macbook Air?!)

@tvpmb

Tested on MBP, Win8 VMWare, Chrome stable:

'ontouchstart' in window? true

document instanceof DocumentTouch ? false

MQ? false
@tvpmb

@stucox FWIW - Just tested the codepen link on an iPad, identical results to the Win8 virtual machine/Chrome stable.

@tvpmb

iOS (iphone/ipad) console:

typeof window.Touch
"object"

Windows 8 VM, Chrome Stable console:

typeof window.Touch
"function"

OSX, Chrome Stable, Safari latest, console:

typeof window.Touch
"undefined"

From these results, it seems like you could infer that the "object" was created by the OS, because it is/has a touch screen. When it does not need to be created, like on the virtual machine, it appears the browser, just leaves the "function" un-executed... I could be wrong though, just the observations telling me what to do.

@tvpmb

PR Here: #920

@tvpmb

I continued to look at alternative ways to properly detect this. I tried window.matchMedia('(pointer:coarse)'); as well as window.matchMedia('(hover)');. Both of these also failed the tests on the Win8 Surface Pro.

@stucox
Owner

@woutergovaert – the results you saw... were they in a VM by any chance?

Chrome and FF on Win 8 on BrowserStack report false for Modernizr.touch, and false for all 3 line in the Codepen above... so I don't believe these browsers naturally expose the ontouchstart API on Win 8. I wonder if VMWare is telling Win 8 it has a touchscreen regardless...

@woutergovaert
@tvpmb
@dmethvin

Well, something strange is going on. I have a Windows 8 notebook with touch, and in Chrome 26 ("Emulate touch events" disabled) I can attach a handler to window.ontouchstart. A mouse click won't trigger the handler but a tap on the screen will. So the current Modernizr detect is working fine, there really is touch event support. The only teeny tiny issue seems to be that Chrome isn't able to detect when there is no touch hardware, or the VM is lying to it.

@RByers

The way this is supposed to be working in Chrome is as follows:
Touch APIs are present (eg. "'ontouchstart' in window" is true) if and only if:
1) --touch-events=enable flag is set (see about:flags)
2) --touch-events=auto (the default) and the OS reports there is a touchscreen available on chrome startup

On Windows we use the GetSystemMetrics(SM_DIGITIZER) API and see if it returns NID_READY | NID_INTEGRATED_TOUCH (source here: https://code.google.com/p/chromium/codesearch#chromium/src/ui/base/touch/touch_device_win.cc&q=IsTouchDevicePresent&sq=package:chromium&type=cs&l=12). It sounds to me like Windows 8 is returning this as true even when there's no touchscreen? I hear having the Visual Studio simulator installed can cause Windows to lie and behave as if there is a touchscreen when there isn't (http://stackoverflow.com/questions/13004911/how-to-specifically-detect-a-touch-screen-display-on-windows-8), any chance that's what's going on?

@fitli65

@stucox: Sorry for my late reply!
My computer says: (with 27" Samsung SyncMater P2770HD Monitor)


'ontouchstart' in window? true
document instanceof DocumentTouch? false
MQ? false


@RByers: In my Programmslist I see: Visual Studio 2008 x64 Redistributables
Is this the simulator?

@stucox
Owner

Thanks for the info all.

@tvpmb – could you give us some more details about a) the VM setup you're using (including settings/services in use) and b) the Toshiba laptop you also saw a problem on? (again, services in use)

Apparently the SMART Board service and some other virtual touch drivers can also cause the OS to report that a touch device is connected.


It looks likely that this will be moved to a Chromium ticket, or some tickets aimed at various vendors. Modernizr's doing its job here: detecting the Touch Events APIs.

Ultimately, this is yet another reason why Modernizr.touch / 'ontouchstart' in window shouldn't be used to detect touch devices... there are too many variables at play to reliably assume presence of the APIs and the presence of a touch input will always correlate.

@tagawa

If you need further reports... a clean instance of Win 8 (not touchscreen, not a VM) with Firefox 20 returns true for all three lines in the CodePen link ( http://codepen.io/anon/pen/JAsdy ). IE 10 returns false for all three of them.

@pixelkritzel

I, also don't have a real Win( machine. Who does?

But in Win8, the Image from modern.ie, and Paralells all the test return false in IE10 and FF20.

@tvpmb

@stucox The virtual machine is just a bone stock Win8 Developer's Preview from Microsoft. It is installed using VMWare Fusion 5.03. Nothing else is installed but Chrome stable.

The Toshiba laptop is a 17" Satellite p875-s7200. Aside from that I don't have much more information, except it was running Chrome stable. It belongs to a friend of a friend, so getting my hands on it will be harder, but they experienced this problem in our live application the other day.

IE 10 does work properly, so this one is a bit of a bummer altogether.

@stucox
Owner

Thanks.

As I say, I'm not treating this as a Modernizr bug... it looks like it's detecting the API correctly. But I'm still keen to get to the bottom of it.

What's your use case?

@dmethvin

Above, @RByers said how they're detecting touch. It uses SM_DIGITIZER. If you read the [MSDN page](http://msdn.microsoft.com/en-us/library/windows/desktop/ms724385(v=vs.85\).aspx) it has this description:

SM_DIGITIZER: Nonzero if the current operating system is Windows 7 or Windows Server 2008 R2 and the Tablet PC Input service is started; otherwise, 0. The return value is a bitmask that specifies the type of digitizer input supported by the device.

I looked on my Windows 8 PC and there is no such service, but there is the "Touch Keyboard and Handwriting Panel Service" which sounds similar. Go to Control Panel, Administrative Tools, Services and find that service. Stop it, restart the browser, and see if that makes the problem go away. If so, set the service to Disabled so it won't restart.

@tvpmb
@dmethvin

I have made a detection script, you can get it here: https://dl.dropboxusercontent.com/u/2024878/dtouch.exe

Run that in your Windows 8 VM and see what it says. On my touch-capable Windows 8 system I get this:

SM_DIGITIZER: 0x000000c1 (193)
SM_MAXIMUMTOUCHES: 0x0000000a (10)
SM_TABLETPC: 0x00000001 (1)

If you get anything other than zero, it means that Windows thinks the system is touch capable. The [MSDN page](http://msdn.microsoft.com/en-us/library/windows/desktop/ms724385(v=vs.85\).aspx) has the bitmap decoding for the SM_DIGITIZER value, that may tell a bit more about why it is reporting that. But if you DO get something other than zero then I agree with @stucox that it's not a Modernizr problem or even a Chrome problem.

@fitli65

Hello all

I don't think this is only a WIN8 Problem...
I get thes results from the CodePen Test:

Chrome: 26
'ontouchstart' in window? true
document instanceof DocumentTouch? false
MQ? false

Firefox: 20
'ontouchstart' in window? true
document instanceof DocumentTouch? true
MQ? true

Safari: 5.1
'ontouchstart' in window? false
document instanceof DocumentTouch? false
MQ? false

IE10:
'ontouchstart' in window? false
document instanceof DocumentTouch? false
MQ? false

On my Laptop (HP HDX18 and also Win8 installed) I don't have any problems!

@dmethvin: I dont't find a service like this in german system... and your dtouch.exe doesn't work on my computer... It says MSVCR110.dll is missing an has to be installed...
Any idea what this could be?

@stucox
Owner

@fitli65 said:

I don't think this is only a WIN8 Problem...

The results I've seen so far in this thread suggest to me that Chrome and Firefox are probably both using the same Windows system parameter(s) to determine the presence of a touchscreen, and that there are cases when these can't be trusted.

Safari and IE10 don't support the Touch Events API, so we'd expect them to return false for all of these tests anyway.

I agree we shouldn't assume that it's solely Win 8 which could be affected by this kind of thing though... any platform could suffer from inconsistent settings and services messing with things.

@fitli65

I found the problem!

On my computer I tested the Logitech Wireless Touchpad T650 a while ago. But did not use it much... So I removed it again. But I found out, that in the Logitech Unifying Software the Touchpad was already there and I had to unlock it first. After a reboot Firefox and Chrome act normal again! :o)
Looks like Safari and IE did not care about this.

Maybe this info helps others ;o)

@egirard

Glad to hear that things are fixed, fitli65. Were you able to run the diagnostic that dmethvin posted? -https://dl.dropboxusercontent.com/u/2024878/dtouch.exe

I'd be very curious to know what the "Logitech Wireless Touchpad T650" is reporting under SM_DIGITIZER.

@fitli65

@egirard: No, I was not able to run the tool... I got the error message: " MSVCR110.dll is missing an has to be installed"

@dmethvin

Try it now, I recompiled with static linking to circumvent DLL Hell. https://dl.dropboxusercontent.com/u/2024878/dtouch.exe

@fitli65

@dmethvin: Sorry! But I don't have the Touchpad anymore... Now (after unlocking it) my computer sais:

SM_DIGITIZER: 0x00000000 (0)
SM_MAXIMUMTOUCHES: 0x00000000 (0)
SM_TABLETPC: 0x00000000 (0)

@egirard

The SM_DIGITIZER flag is used by Chrome to decide if there's a touch screen active and available. Specifically, we're looking for NID_INTEGRATED_TOUCH (0x01) and NID_READY (0x80).

Thanks for patching the utility, @dmethvin - this makes for an excellent diagnostic tool.

@stucox
Owner

To wrap up:

The consensus here seems to be that these are instances whereby the browser is fooled into thinking a touch device connected. Modernizr certainly can't do anything about this and I suspect there's not a lot the browsers can do either.

However, if anyone has sufficient information to chase this up with driver and VM vendors, that'd be great.

In any case, Modernizr.touch is doing its job here: detecting support for the Touch Events API.

See my blog post on the issue of detecting touchscreen devices here: http://www.stucox.com/blog/you-cant-detect-a-touchscreen/

@stucox stucox closed this
@grantzau

Just had the same problem when testing a project on PC Win 7, Chrome 27

I have drivers installed for a "pen" and even though it's not connected to the computer, Chrome somehow thinks, that it should support Touch Events. (Earlier versions of Chrome didn't do this.)

Thanks to the comments above I looked at the services running on the PC and after stopping the service "Tablet PC Input Service" and restarting Chrome, the "no-touch" class was added again.

So, as also mentioned in comments above, it's a problem in the way Chrome (and maybe other browsers) determines, if the OS has a touch device connected.

@stucox
Owner

Ok thanks, I'll pass this info on to the Chrome team – although, as stated earlier, Chrome gets this information from the OS, so there probably isn't a lot they can do about it.

Again, it seems to be better all round if we don't treat the presence of touch APIs as a reliable test of whether or not the device has a touchscreen.

@jerbob92 jerbob92 referenced this issue from a commit in gitlabhq/gitlabhq
@dblessing dblessing Mobile UI improvements for dashboard/nav
Style navbar toggle button

Style navbar toggle manually instead of with button classes

Style navbar

Modify color

Turn off all tooltips for touch devices

Style main nav

Fix scrolling navbar collapse

Style tweaks

Minor tweaks

Style no ssh key message
8b3b6f1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.