How to detect that the browser has no mouse and is touch-only with JavaScript?

Spread the love

Sometimes, we want to detect that the browser has no mouse and is touch-only with JavaScript.

In this article, we’ll look at how to detect that the browser has no mouse and is touch-only with JavaScript.

How to detect that the browser has no mouse and is touch-only with JavaScript?

To detect that the browser has no mouse and is touch-only with JavaScript, we use the window.matchMedia method.

For instance, we write

if (window.matchMedia("(any-hover: none)").matches) {
  //...
}

to call matchMedia with "(any-hover: none)" to detect devices that has no hover capability.

Conclusion

To detect that the browser has no mouse and is touch-only with JavaScript, we use the window.matchMedia method.

Leave a Reply

Your email address will not be published. Required fields are marked *