如何仅检测本机 Android 浏览器 [英] How to detect only the native Android browser

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

问题描述

检测 Android 设备很容易,但我无法仅检测 Android 本机浏览器.问题是 Dolphin 浏览器具有几乎相同的用户代理字符串,我想知道他们是否使用本机浏览器..

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..

这可能吗?

推荐答案

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

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 中的 chrome,尽管现在在很多设备上,chrome 被用作默认浏览器.

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));

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

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