As Philippe says, you can't statically determine, from the outset, whether
the user's device supports touch or not – you can only determine whether
the browser supports touch (and nowadays most do).

What you *can *do is reserve assumption until a touch event occurs, then
set the class (or set it to localStorage, so that subsequent page loads
don't have to wait). Not sure how much this will help you in practice:

document.addEventListener( 'touchstart', function addClass(){
  document.documentElement.classList.add( 'touch-support' );
  document.removeEventListener( 'touchstart', addClass );
} )


Regards,
Barney Carroll

barney.carr...@gmail.com
+44 7429 177278

barneycarroll.com

On 4 February 2015 at 00:10, Tom Livingston <tom...@gmail.com> wrote:

> Thanks Philippe
> On Tue, Feb 3, 2015 at 7:05 PM Philippe Wittenbergh <e...@l-c-n.com>
> wrote:
>
> >
> > > Le 4 févr. 2015 à 05:58, Tom Livingston <tom...@gmail.com> a écrit :
> > >
> > > I am using Modernizr and it's html classes 'touch' and 'no-touch' in
> > > my CSS to add/hide functionality via such as a fixed menu bar on
> > > desktop and a relative menu bar on mobile, among other things.
> > >
> > > The issue I am having is that in Chrome 40.X and FF 35.0.1 in Win 8.1,
> > > I am getting a false 'touch' class (as opposed to 'no-touch') on a
> > > desktop setup.
> >
> > That has been an issue since at least chrome 30 and Firefox 10 or
> > something.
> > The thing is, Modernizr detects if the browser supports touch events, not
> > if the user has a touch screen…
> >
> > An intro
> > http://www.stucox.com/blog/you-cant-detect-a-touchscreen/
> >
> > Modernizr ticket:
> > https://github.com/Modernizr/Modernizr/issues/548
> >
> > > Googling hasn't been helpful yet and am wondering if anyone has over
> > > come this issue or has an idea.
> >
> > Uh? Lots of hits on DDG (many stackoverflow pages)
> >
> > http://stackoverflow.com/questions/13530612/modernizr-
> > reporting-laptop-as-touch-device-in-chrome-and-ff
> > http://stackoverflow.com/questions/4817029/whats-the-
> > best-way-to-detect-a-touch-screen-device-using-javascript/4819886#4819886
> >
> > In short: touch/no-touch are useless.
> >
> > Future MQ, but I have no idea if this tentatively supported anywhere:
> > http://dev.w3.org/csswg/mediaqueries-4/#mf-interaction
> >
> > Philippe
> > --
> > Philippe Wittenbergh
> > http://l-c-n.com/
> >
> >
> >
> >
> >
> >
> ______________________________________________________________________
> css-discuss [css-d@lists.css-discuss.org]
> http://www.css-discuss.org/mailman/listinfo/css-d
> List wiki/FAQ -- http://css-discuss.incutio.com/
> List policies -- http://css-discuss.org/policies.html
> Supported by evolt.org -- http://www.evolt.org/help_support_evolt/
>
______________________________________________________________________
css-discuss [css-d@lists.css-discuss.org]
http://www.css-discuss.org/mailman/listinfo/css-d
List wiki/FAQ -- http://css-discuss.incutio.com/
List policies -- http://css-discuss.org/policies.html
Supported by evolt.org -- http://www.evolt.org/help_support_evolt/

Reply via email to