Javascript 仅自动检测移动浏览器(通过用户代理?)而非平板电脑

Javascript 仅自动检测移动浏览器(通过用户代理?)而非平板电脑,javascript,android,jquery,mobile,responsive-design,Javascript,Android,Jquery,Mobile,Responsive Design,我只想将meta标签应用于移动设备,而不是平板电脑。其目的是缩小mobie设备中的页面。我得到以下条件,但问题是它也适用于平板电脑,因为也有android平板电脑 <script> if(navigator.userAgent.match(/Android/i) || navigator.userAgent.match(/webOS/i) || navigator.userAgent.match(/iPhone/i) || navigator.userAgent.

我只想将meta标签应用于移动设备,而不是平板电脑。其目的是缩小mobie设备中的页面。我得到以下条件,但问题是它也适用于平板电脑,因为也有android平板电脑

<script>
    if(navigator.userAgent.match(/Android/i)
  || navigator.userAgent.match(/webOS/i)
  || navigator.userAgent.match(/iPhone/i)
  || navigator.userAgent.match(/iPod/i)
  || navigator.userAgent.match(/BlackBerry/i)
  || navigator.userAgent.match(/Windows Phone/i)) {
    document.write('<meta name="viewport" content="width=device-width, user-scalable=yes, initial-scale=0.25" />');
}
    </script>

if(navigator.userAgent.match(/Android/i)
||navigator.userAgent.match(/webOS/i)
||navigator.userAgent.match(/iPhone/i)
||navigator.userAgent.match(/iPod/i)
||navigator.userAgent.match(/BlackBerry/i)
||navigator.userAgent.match(/windowsphone/i)){
文件。写(“”);
}
我知道这是一个老问题,但我找不到相关的答案。

移动Android在用户代理标题中有“Mobile”字符串。Android平板电脑则不然。因此,要想只使用手机,你需要搜索“手机”和“安卓”两个词。然而,有一些平板电脑公司正在脱离这一惯例,因此对于XOOM等平板电脑公司,如果要检测这些平板电脑,您需要检查平板电脑的型号

您还可以查看以下内容:。我认为这样做可能会有所帮助,比如:

<script type='text/javascript' src="//wurfl.io/wurfl.js"></script>

if(WURFL.form_factor != "Tablet"){
     // do mobile things here
}

我认为你走错了方向。我会考虑使用css使你的网站真正具有响应性。查看bootstrap responsive Grid我们在平板电脑前已经使网站具有响应性,但我们有不同的移动设备网站,这就是为什么我只想缩小移动设备的页面。这是一个很好的解决方案,但我不能使用任何插件。还有其他解决方案吗?正如我在第一部分中所说的,我认为唯一的解决方案是在用户代理中测试移动字符串,然后在您知道的没有该关键字的设备中测试设备名称
{
 "complete_device_name":"Samsung Galaxy Tab",
 "is_mobile":true,
 "form_factor":"Tablet"
}