You can use the JA Categorizr library to check if the user device is a mobile phone, tablet, smart TV or desktop. Categorizr uses sniffing a user agent, so you should keep an eye on script updates as user agents tend to “evolve” over time.
Here's how you could use Categorizr to check if the user is on a smartphone, but not a smart TV, desktop, or tablet:
if (categorizr.isMobile) { //run this code if on a phone } else { //run this code if not on a phone }
source share