如何使用 javascript 检测 kindle fire?

发布于 2025-01-01 05:22:32 字数 416 浏览 9 评论 0原文

我正在尝试使用 javascript 检测我的网站是否在 kindle fire 移动设备上运行。我尝试过 navigator.userAgent 和 navigator.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

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

我可以使用这些字符串来知道我在 kindle 上而不是在其他设备上?

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 :

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

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

小帐篷 2025-01-08 05:22:33

在 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
}

in 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
}
断爱 2025-01-08 05:22:33

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

在 Silk 模式下:

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

The User Agent String for Kindle Fire is:

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
旧城烟雨 2025-01-08 05:22:33

有两件事你应该检查
1/ Silk(或 Silk-Accelerated)
2/“Kindle”、“KFOT”、“KFTT”或 https 中的表中的其他内容: //developer.amazon.com/sdk/fire/specifications.html

在 Silk 或 pass-through 中,#1 应该给您确认,如果从 WebView 访问网页,则 ​​#2 会捕获它

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

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

痴情 2025-01-08 05:22:33

一个问题是亚马逊会更改每个新型号的字符串。您可以仅检查 Kindle、Silk 和 KF*,但这可能会导致误报。我对上面的示例之一的代码进行了一些修改,使其更具可读性且易于维护。

截至 2015 年 11 月 18 日,以下代码应该可以运行。

检查https://developer.amazon.com/sdk/fire/specifications.html 对于新型号。

这是我编写的代码,用于将人们从我的 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>

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.

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

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

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

<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>
成熟稳重的好男人 2025-01-08 05:22:33

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

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/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文