如何使用 javascript 检测 kindle fire?
我正在尝试使用 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
在 JavaScript 中,
in Javascript ,
Kindle Fire 的用户代理字符串为:
在 Silk 模式下:
The User Agent String for Kindle Fire is:
In Silk mode:
有两件事你应该检查
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
一个问题是亚马逊会更改每个新型号的字符串。您可以仅检查 Kindle、Silk 和 KF*,但这可能会导致误报。我对上面的示例之一的代码进行了一些修改,使其更具可读性且易于维护。
截至 2015 年 11 月 18 日,以下代码应该可以运行。
检查https://developer.amazon.com/sdk/fire/specifications.html 对于新型号。
这是我编写的代码,用于将人们从我的 Kindle Fire 和 Android 手机网站重定向到我的游戏 Luna Puma:
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:
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/