如何检测只有原生的Andr​​oid浏览器 [英] How to detect only the native Android browser

查看:220
本文介绍了如何检测只有原生的Andr​​oid浏览器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可以很容易地检测到Android设备,但我有麻烦只检测了Android原生浏览器。问题是海豚浏览器有一个几乎相同的用户代理字符串,我想一个办法,如果他们使用的是原生浏览器或不知道..

it's easy to detect the Android device, but I am having trouble detecting ONLY the Android native browser. Problem is the Dolphin browser has an almost identical user-agent string, and I'd like a way to know if they are using the native browser or not..

这可能吗?

推荐答案

您只需要测试用户代理字符串的几个部分,以确保您有默认的A​​ndr​​oid浏览器:

you simply need to test a few parts of the user agent string in order to make sure you have the default android browser:

var nua = navigator.userAgent;
var is_android = (nua.indexOf('Mozilla/5.0') > -1 && nua.indexOf('Android ') > -1 && nua.indexOf('AppleWebKit') > -1);

您可以使用以下,以确保您没有在Android的搭配镀铬,虽然很多现在的设备,铬被用作默认浏览器。

you can use the following to ensure that you do not match chrome within android, although on a lot of devices now, chrome is being used as the default browser.

var nua = navigator.userAgent;
var is_android = ((nua.indexOf('Mozilla/5.0') > -1 && nua.indexOf('Android ') > -1 && nua.indexOf('AppleWebKit') > -1) && !(nua.indexOf('Chrome') > -1));

编辑: 如果你想防止区分大小写,您可以使用以下命令:

If you want to protect against case sensitivity, you can use the following:

var nua = navigator.userAgent.toLowerCase();
var is_android = ((nua.indexOf('mozilla/5.0') > -1 && nua.indexOf('android ') > -1 && nua.indexOf('applewebkit') > -1) && !(nua.indexOf('chrome') > -1));

这篇关于如何检测只有原生的Andr​​oid浏览器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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