14

I read this about interaction media which is explain how css can detect if pointer is touchscreen or not. It's using @media query like

@media (pointer: coarse){ body{ // do something } } 

but I just wonder how to implementing it using javascript ot JQuery, is it possible?

Thank you

1 Answer 1

23
is_fine = matchMedia('(pointer:fine)').matches is_coarse = matchMedia('(pointer:coarse)').matches 

Works in Chrome for me.

Sign up to request clarification or add additional context in comments.

3 Comments

Alternatively you can style some element with CSS and check whether that style is applied via JS.
window.matchMedia() should be well supported: developer.mozilla.org/en-US/docs/Web/API/Window/matchMedia – basically if the CSS method works, the matchMedia() should also work.
Would be nice if there was a more native JavaScript API for determining input devices, without having to go via ` matchMedia`, but I could not find one.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.