开发者

How do you detect a mobile device with javascript?

开发者 https://www.devze.com 2023-02-01 03:40 出处:网络
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 s

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

精彩评论

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

关注公众号