0

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

  • UA 嗅探

  • jQuery的width()

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

我需要根据查看页面的移动设备的宽度更改页面的 HTML。我不能单独使用媒体查询来做到这一点。

4

3 回答 3

2

您可以使用移动检测 JS 库来执行此操作。注意警告:

// 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.
于 2013-01-17T13:14:33.240 回答
0

有两种选择:

1- 用户代理嗅探。2-手机检测JS库

于 2013-01-17T12:57:46.440 回答
0

您刚刚回答了自己的问题 - 您要么想采用用户的浏览器,要么采用他们的设备宽度。

如果您想在宽度小于 WIDTH_CONSTANT 时执行某些操作,请使用 mediaQueries,或使用 javascript 检查尺寸。

现在不建议在客户端进行用户代理嗅探,因为您需要寻找您感兴趣的功能,而不是嗅探用户代理。

所以在你的情况下,我几乎有信心说你应该寻找设备宽度。

PS如果您在服务器端进行交易,我认为用户代理嗅探将是了解设备用户正在使用的唯一方法。

于 2013-01-17T13:10:59.253 回答