matthewhudson / current-device

📱 The easiest way to write conditional CSS and/or JavaScript based on device operating system (iOS, Android, Blackberry, Windows, Firefox OS, MeeGo), orientation (Portrait vs. Landscape), and type (Tablet vs. Mobile).
https://matthewhudson.github.io/current-device/
MIT License
3.94k stars 587 forks source link

Problem with touch-enabled Windows laptops #64

Open wilei opened 10 years ago

wilei commented 10 years ago

I've met some problems with device.js's way to detect Windows Tablets.

Detection is done correctly in some cases, but when user has a Windows laptop, with touchscreen and Win8 (or 8.1) device.js detects user as tablet user. And some cases that detection is wrong, as user should be detected as desktop user, instead of tablet user.

One (maybe the only) way to handle this, for now, is to detect these users by OS architecture. ARM is tablet and Win64, x86 and wow64 are desktops.

Sample UA-string for some Lenovo model:

Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; Win64; x64; Trident/6.0; Touch; MALNJS)
mchambaud commented 10 years ago

I'm having a similar issue with a VMWare install.

swatkins commented 10 years ago

Same issue here - UA-String from my test device:

"Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; Touch; MATBJS; rv:11.0) like Gecko"

windowsTablet function checks for "touch" in the string to determine "tablet"

ghost commented 10 years ago

I was investigating this just yesterday, and from what I found, the user agent reported for many Windows 8 tablets and touch-enabled laptops are the virtually the same. It may not be possible to accurately differentiate tablets from desktops without having to match device codes (which would suck).

ghost commented 10 years ago

I think checking for the ARM string might be enough. Because tablets most likely run on Win RT. Link: http://msdn.microsoft.com/en-us/library/ie/hh920767%28v=vs.85%29.aspx

ghost commented 10 years ago

Combined sales of Msft/3rd party Windows tablets show the Pro/Intel versions selling much better than the Surface RT on ARM. Checking for ARM will at least flag the Surface RT as a tablet correctly, but tablets, in the Msft world still "most likely" are Intel.

matthewhudson commented 10 years ago

ATTN: @chrismbeckett @netlovers @swatkins @mchambaud @wilei

From what I can tell, there is no reliable way to distinguish between Windows "Tablet" vs "Touch".

Perhaps a note should be added to the README, and the functions/classes renamed - thoughts?

ghost commented 10 years ago

A note in the README sounds fine, I guess. But at least the ARM versions should be filtered out, so the script would be a bit more correct.

wilei commented 10 years ago

On our use-case (which uses forked version of device.js) reason to seperate ARM devices from other Win8 devices is just because ARM devices are so slow -> we drop some of JS-features from those.

So I prefer note in README and ability to check if device is ARM device.

ghost commented 10 years ago

I found 1 article that suggests doing feature detection for ActiveX since it is only on desktop, but that won't work for all browsers. In the end, for my own fork I am going to add the ARM check, and my final fallback is going to look at screen.width / devicePixelRatio or something to detect resolutions > 1200px. This would work when a tablet is hooked to a higher resolution ext monitor to provide a desktop experience.