2

I know that most people try to avoid Javascript mobile detection because not all mobile browsers support it, but I am using it in a Javascript function so if the browser doesn't support Javascript, it doesn't matter if it's mobile since it won't be able to use the function. I don't want it to redirect; just to return whether the browser is mobile or not. Any ideas?

3
  • 2
    What do you mean by, "return"? What is it in particular about a device's "mobileness" that's interesting to you? Commented Dec 23, 2010 at 16:10
  • I mean I want something along the lines of function isMobile() that returns true if it is mobile or false if it is not. As for the "mobileness", I am specifically trying to find touch screen mobile devices. The function I am working on is a "tooltip" function, and I'd either want to change the displaying of the tooltip to only on the click of the question mark icon or even disable it all together and not even display the icon. Commented Dec 23, 2010 at 16:16
  • Most mobile browsers support JavaScript nowadays. You probably not want to detect mobile browsers, but JavaScript-less browsers. The best solution would be build your site to work with any JavaScript at all, and then add JavaScript for additional features on top. Commented Dec 23, 2010 at 16:21

3 Answers 3

3
var isTouchDevice = ('ontouchstart' in window) || window.DocumentTouch && document instanceof DocumentTouch; 

in modernizr ,it is like this.

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

1 Comment

there are some laptop with touch screen, so this is really a touch device detector.
1

See: Standard way to detect mobile browsers in a web application based on the http request

Comments

1

You can use handsetdetection.com to detect mobile browsers in javascript. We do a detection based on the http headers and send javascript to the client. (disclaimer, i work there).

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.