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?
- 2What do you mean by, "return"? What is it in particular about a device's "mobileness" that's interesting to you?Pointy– Pointy2010-12-23 16:10:47 +00:00Commented 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.Zak– Zak2010-12-23 16:16:56 +00:00Commented 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.RoToRa– RoToRa2010-12-23 16:21:01 +00:00Commented Dec 23, 2010 at 16:21
Add a comment |
3 Answers
var isTouchDevice = ('ontouchstart' in window) || window.DocumentTouch && document instanceof DocumentTouch; in modernizr ,it is like this.
1 Comment
ZHAO Xudong
there are some laptop with touch screen, so this is really a touch device detector.
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).