开发者

How do you detect a mobile device with javascript?

I know that most people try to avoid Javascript mobile detection because not all mobile browsers support 开发者_StackOverflowit, 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?


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

in modernizr ,it is like this.


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


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).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜