如何使用javascript检测kindle fire ?

时间:2021-08-21 06:40:42

I'm trying to detect with javascript if my website is running on a kindle fire mobile device. I've tried with navigator.userAgent and navigator.appVersion but I get this results on kindle :

我试图用javascript检测我的网站是否运行在kindle fire移动设备上。我试着与导航。userAgent和导航。appVersion但是我在kindle上得到了这个结果:

5.0 (Macintosh; U; Intel Mac OS X 10_6_3; en-us) AppleWebKit/533.16 (KHTML, like Gecko) Version/5.0 Safari/533.16

5.0(麦金塔电脑;U;英特尔Mac OS X 10_6_3;-us) AppleWebKit/533.16 (KHTML,像Gecko)版本/5.0 Safari/533.16。

and

Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_3; en-us) AppleWebKit/533.16 (KHTML, like Gecko) Version/5.0 Safari/533.16

Mozilla / 5.0(麦金塔电脑;U;英特尔Mac OS X 10_6_3;-us) AppleWebKit/533.16 (KHTML,像Gecko)版本/5.0 Safari/533.16。

What can I use form those strings to know that I'm on a kindle and not on other device?

我能用这些弦来知道我在kindle上而不是在其他设备上吗?

6 个解决方案

#1


6  

The User Agent String for Kindle Fire is:

Kindle Fire用户代理字符串为:

Mozilla/5.0 (Linux; U; Android 2.3.4; en-us; Kindle Fire Build/GINGERBREAD) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1

In Silk mode:

在丝绸模式:

Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_3; en-us; Silk/1.1.0-80) AppleWebKit/533.16 (KHTML, like Gecko) Version/5.0 Safari/533.16 Silk-Accelerated=true

#2


15  

in Javascript ,

在Javascript中,

var ua = navigator.userAgent;
var isKindle = /Kindle/i.test(ua) || /Silk/i.test(ua) || /KFTT/i.test(ua) || /KFOT/i.test(ua) || /KFJWA/i.test(ua) || /KFJWI/i.test(ua) || /KFSOWI/i.test(ua) || /KFTHWA/i.test(ua) || /KFTHWI/i.test(ua) || /KFAPWA/i.test(ua) || /KFAPWI/i.test(ua);
if(isKindle) { 
//Your code here
}

#3


7  

there are two things you should check for 1/ Silk (or Silk-Accelerated) 2/ "Kindle", "KFOT", "KFTT" or others from the table at https://developer.amazon.com/sdk/fire/specifications.html

在https://developer.amazon.com/sdk/fire/ations.html中,你应该检查1/ Silk(或丝绸加速)2/“Kindle”、“KFOT”、“KFTT”或其他表格中的内容

In Silk or pass-through #1 should give you confirmation, if the web page is being accessed from a WebView then #2 will catch it

在Silk或pass-through #1中应该给出确认,如果从WebView访问web页面,那么#2将捕获它

#4


2  

One problem is that Amazon changes the strings for every new model. You could check only for Kindle, Silk and KF* but that could potentially lead to false positives. I have altered the code a bit from one of the examples above to make a bit more readable and easy to maintain.

一个问题是,Amazon更改了每个新模型的字符串。你只能检查Kindle、Silk和KF*,但这可能会导致误报。我对上面示例中的代码做了一点修改,使代码更易于阅读和维护。

As of November 18, 2015, the below code should work.

到2015年11月18日,以下代码应该可以工作。

Check https://developer.amazon.com/sdk/fire/specifications.html for new models.

检查https://developer.amazon.com/sdk/fire/ations.html以获得新模型。

This is the code I wrote to redirect people to my game Luna Puma from my website for both Kindle Fire and Android phones:

这是我在我的网站上为Kindle Fire和Android手机写的代码,用来引导人们转到我的游戏Luna Puma:

<script type="text/javascript"> // <![CDATA[

   var ua = navigator.userAgent;

   var kindleStrings = [ 
    "Kindle",
    "Silk",
    "KFTT",
    "KFOT",
    "KFJWA",
    "KFJWI",
    "KFSOWI",
    "KFTHWA",
    "KFTHWI",
    "KFAPWA",
    "KFAPWI",
    "KFASWI",
    "KFTBWI",
    "KFMEWI",
    "KFFOWI",
    "KFSAWA",
    "KFSAWI",
    "KFARWI" ];

   var isKindle = false;

   for (index = 0; index < kindleStrings.length; index++) {
       var matchRegExp = new RegExp (kindleStrings[index]);
       if (matchRegExp.test (ua)) {
           isKindle = true;
           break;
       }
  }

   if (isKindle) { 
        document.location = "amzn://apps/android?asin=B01859LRE0";
   }

   var isAndroid = /Android/i.test (ua);

   if (isAndroid && !isKindle) {
      document.location = "https://play.google.com/store/apps/details?id=com.xanamania.lunapuma";
   } // ]]>

 </script>

#5


1  

Detecting whether you're running on a Kindle Fire is much more complicated than detecting other platforms, as the user agent can wear many disguises.

检测你是否在Kindle Fire上运行要比检测其他平台复杂得多,因为用户代理可以穿很多伪装。

I wrote this is-mobile component that can detect whether you are running on Kindle Fire, and other platforms as well.

我写的这个is-mobile组件可以检测你是否在Kindle Fire以及其他平台上运行。

Feel free to import it and use as shown in these examples:

如下列例子所示,请随意导入和使用:

isMobile.Android() => true/false
isMobile.iOS() => true/false
isMobile.any() => true/false
isMobile.KindleFire() => true/false
isMobile.BlackBerry() => true/false

#6


0  

The Silk User-Agent and example JavaScript code to detect Silk can be found on the blog: http://amazonsilk.wordpress.com/useful-bits/silk-user-agent/

Silk用户代理和用于检测Silk的示例JavaScript代码可以在博客http://amazonsilk.wordpress.com/useful-bits/silk-user-agent/上找到

#1


6  

The User Agent String for Kindle Fire is:

Kindle Fire用户代理字符串为:

Mozilla/5.0 (Linux; U; Android 2.3.4; en-us; Kindle Fire Build/GINGERBREAD) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1

In Silk mode:

在丝绸模式:

Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_6_3; en-us; Silk/1.1.0-80) AppleWebKit/533.16 (KHTML, like Gecko) Version/5.0 Safari/533.16 Silk-Accelerated=true

#2


15  

in Javascript ,

在Javascript中,

var ua = navigator.userAgent;
var isKindle = /Kindle/i.test(ua) || /Silk/i.test(ua) || /KFTT/i.test(ua) || /KFOT/i.test(ua) || /KFJWA/i.test(ua) || /KFJWI/i.test(ua) || /KFSOWI/i.test(ua) || /KFTHWA/i.test(ua) || /KFTHWI/i.test(ua) || /KFAPWA/i.test(ua) || /KFAPWI/i.test(ua);
if(isKindle) { 
//Your code here
}

#3


7  

there are two things you should check for 1/ Silk (or Silk-Accelerated) 2/ "Kindle", "KFOT", "KFTT" or others from the table at https://developer.amazon.com/sdk/fire/specifications.html

在https://developer.amazon.com/sdk/fire/ations.html中,你应该检查1/ Silk(或丝绸加速)2/“Kindle”、“KFOT”、“KFTT”或其他表格中的内容

In Silk or pass-through #1 should give you confirmation, if the web page is being accessed from a WebView then #2 will catch it

在Silk或pass-through #1中应该给出确认,如果从WebView访问web页面,那么#2将捕获它

#4


2  

One problem is that Amazon changes the strings for every new model. You could check only for Kindle, Silk and KF* but that could potentially lead to false positives. I have altered the code a bit from one of the examples above to make a bit more readable and easy to maintain.

一个问题是,Amazon更改了每个新模型的字符串。你只能检查Kindle、Silk和KF*,但这可能会导致误报。我对上面示例中的代码做了一点修改,使代码更易于阅读和维护。

As of November 18, 2015, the below code should work.

到2015年11月18日,以下代码应该可以工作。

Check https://developer.amazon.com/sdk/fire/specifications.html for new models.

检查https://developer.amazon.com/sdk/fire/ations.html以获得新模型。

This is the code I wrote to redirect people to my game Luna Puma from my website for both Kindle Fire and Android phones:

这是我在我的网站上为Kindle Fire和Android手机写的代码,用来引导人们转到我的游戏Luna Puma:

<script type="text/javascript"> // <![CDATA[

   var ua = navigator.userAgent;

   var kindleStrings = [ 
    "Kindle",
    "Silk",
    "KFTT",
    "KFOT",
    "KFJWA",
    "KFJWI",
    "KFSOWI",
    "KFTHWA",
    "KFTHWI",
    "KFAPWA",
    "KFAPWI",
    "KFASWI",
    "KFTBWI",
    "KFMEWI",
    "KFFOWI",
    "KFSAWA",
    "KFSAWI",
    "KFARWI" ];

   var isKindle = false;

   for (index = 0; index < kindleStrings.length; index++) {
       var matchRegExp = new RegExp (kindleStrings[index]);
       if (matchRegExp.test (ua)) {
           isKindle = true;
           break;
       }
  }

   if (isKindle) { 
        document.location = "amzn://apps/android?asin=B01859LRE0";
   }

   var isAndroid = /Android/i.test (ua);

   if (isAndroid && !isKindle) {
      document.location = "https://play.google.com/store/apps/details?id=com.xanamania.lunapuma";
   } // ]]>

 </script>

#5


1  

Detecting whether you're running on a Kindle Fire is much more complicated than detecting other platforms, as the user agent can wear many disguises.

检测你是否在Kindle Fire上运行要比检测其他平台复杂得多,因为用户代理可以穿很多伪装。

I wrote this is-mobile component that can detect whether you are running on Kindle Fire, and other platforms as well.

我写的这个is-mobile组件可以检测你是否在Kindle Fire以及其他平台上运行。

Feel free to import it and use as shown in these examples:

如下列例子所示,请随意导入和使用:

isMobile.Android() => true/false
isMobile.iOS() => true/false
isMobile.any() => true/false
isMobile.KindleFire() => true/false
isMobile.BlackBerry() => true/false

#6


0  

The Silk User-Agent and example JavaScript code to detect Silk can be found on the blog: http://amazonsilk.wordpress.com/useful-bits/silk-user-agent/

Silk用户代理和用于检测Silk的示例JavaScript代码可以在博客http://amazonsilk.wordpress.com/useful-bits/silk-user-agent/上找到