简体   繁体   English

Javascript检测android本机浏览器

[英]Javascript detect android native browser

I want to detect with javascript the native android browser (the one that comes installed on every android phone). 我想用javascript检测本机android浏览器(安装在每个Android手机上的浏览器)。

What should I look for in useragent ? 我应该在useragent中寻找什么?

This should work. 这应该工作。

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

Native browser, we could not detect at the first go itself, using the above mentioned code: 本机浏览器,我们无法在第一次使用上面提到的代码时检测到:

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

as for most devices we got the following as the user agent for chrome browser: 对于大多数设备,我们得到以下作为chrome浏览器的用户代理:

在此输入图像描述

and in the native browser: 并在本机浏览器中:

在此输入图像描述

And carried out this observation for Samsung Galaxy S3, htc desire, Asus Zenfone5. 并对三星Galaxy S3,htc欲望,华硕Zenfone5进行了此次观察。



And found out that the "Chrome/30.0.0.0" or the "chrome/" along withthe version is present for most devces including Zenfone 5, Samsung Galaxy s3. 并且发现“Chrome / 30.0.0.0”或“chrome /”以及版本都适用于包括Zenfone 5,Samsung Galaxy s3在内的大多数产品。 But the "version/" no. 但“版本/”没有。 present in the user agent object is more than enough to differentiate the native and the Chrome. 用户代理对象中存在的内容足以区分本机和Chrome。

We used the following code: 我们使用以下代码:

var ua = navigator.userAgent;
var is_native_android = ((ua.indexOf('Mozilla/5.0') > -1 && ua.indexOf('Android ') > -1 && ua.indexOf('AppleWebKit') > -1) && (ua.indexOf('Version') > -1));

Hope, it's useful for you too... :) 希望,它也对你有用...... :)

有关不同用户代理字符串的概述,请参阅此页面

Try something like this: 尝试这样的事情:

var ua = navigator.userAgent.toLowerCase();
var isAndroid = ua.indexOf("android") > -1; //&& ua.indexOf("mobile");
if(isAndroid) {
  // Do something
}

or 要么

check this url: http://davidwalsh.name/detect-android 检查这个网址: http//davidwalsh.name/detect-android

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM