1

The basic problem is to detect mobile and tablet devices with JavaScript. I have a scrollbar plugin, and I only would like to display it on desktop browsers. I would like to use the mobiles/tablets default scrollbar if possible.

I decided to detect devices without the user-agent string, but focusing on mobile and tablet specific JS properties. Here are the properties I found useful to detect mobile/tablet browsers. I would combine them to make it work as accurate as possible.

  • window.screenX can not be different from 0 on mobile/tablet
  • window.orientation is "undefined" on the most desktop browsers

I you can help me with this, I would appreciate it. Is there any way to detect mobile/tablet browser in more accurate way?

Carrie Kendall
  • 10,761
  • 5
  • 57
  • 79
Patartics Milán
  • 4,442
  • 4
  • 22
  • 32

1 Answers1

0

Here is the link to another SO that covers detecting devices using javascript or jQuery.

Edit: However it does appear to utilize userAgent in the more popular answer. The second most popular answer does not use userAgent. It uses CSS media queries to detect, and Javascript checks against the media query to determine the device.

Hope this helps!

What is the best way to detect a mobile device in jQuery?

Community
  • 1
  • 1
wrxsti
  • 2,944
  • 1
  • 15
  • 27
  • The problem with the mentioned CSS solution that is not working with tablet with screen that is wider that 760px. – Patartics Milán Dec 19 '13 at 13:40
  • Wouldn't it be possible to make multiple media queries for different device sizes, that use different hidden elements to determine wider user agents? – wrxsti Dec 19 '13 at 14:06
  • Also the comment section on that particular answer has several decent nuggets of info such as: if( screen.width <= 480 ) { // is mobile }. You could make multiple conditionals to determine the screen width/devices with the global screen.width property. – wrxsti Dec 19 '13 at 14:09