在没有用户代理嗅探的情况下检测移动浏览器 [英] detecting mobile browser without user agent sniffing

查看:128
本文介绍了在没有用户代理嗅探的情况下检测移动浏览器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

哪种方法可以更可靠地检测移动浏览器?

Which approach is more reliable to detect a mobile browser?

  • UA嗅探

  • UA sniffing

jQuery的width()

据我了解,UA嗅探不是很可靠.

As I understand UA sniffing is not very reliable.

我需要根据查看页面的移动设备的宽度来更改页面的HTML.我不能仅靠媒体查询来做到这一点.

I need to change the HTML for a page according to the width of the mobile device viewing the page. I can't do that with media queries alone.

推荐答案

您可以使用

You can use the mobile detect JS library to do this. Take note of the warning:

// WARNING: 
//   These JavaScript-based device detection features may ONLY work 
//   for the newest generation of smartphones, such as the iPhone, 
//   Android and Palm WebOS devices.
//   These device detection features may NOT work for older smartphones 
//   which had poor support for JavaScript, including 
//   older BlackBerry, PalmOS, and Windows Mobile devices. 
//   Additionally, because JavaScript support is extremely poor among 
//   'feature phones', these features may not work at all on such devices.
//   For better results, consider using a server-based version of this code, 
//   such as Java, APS.NET, PHP, or Ruby.

这篇关于在没有用户代理嗅探的情况下检测移动浏览器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆