How can I detect kindle fire with javascript?
Asked Answered
B

5

10

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?

Bandstand answered 30/1, 2012 at 11:49 Comment(0)
I
6

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
Incandesce answered 30/1, 2012 at 11:56 Comment(2)
Awesome. Can you provide a reg ex that will work as Kindle updates to newer versions?Albinus
The above won't work beyond the first generation Kindle Fire. It would've been nice if Amazon stuck with "Kindle Fire" in their user agent strings, but since Kindle Fire 2nd generation they've moved to cryptic acronyms like KFTT, KFJWI and KFJWA. See here for details: developer.amazon.com/sdk/fire/…Precinct
C
16

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
}
Cullum answered 8/1, 2014 at 23:56 Comment(1)
Condensed version (and updated to include current Kindles as of this comment date): /Kindle|Silk|KFAPW|KFARWI|KFASWI|KFFOWI|KFJW|KFMEWI|KFOT|KFSAW|KFSOWI|KFTBW|KFTHW|KFTT|WFFOWI/i.test(ua)Wessling
I
6

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
Incandesce answered 30/1, 2012 at 11:56 Comment(2)
Awesome. Can you provide a reg ex that will work as Kindle updates to newer versions?Albinus
The above won't work beyond the first generation Kindle Fire. It would've been nice if Amazon stuck with "Kindle Fire" in their user agent strings, but since Kindle Fire 2nd generation they've moved to cryptic acronyms like KFTT, KFJWI and KFJWA. See here for details: developer.amazon.com/sdk/fire/…Precinct
N
6

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

Notation answered 28/9, 2012 at 21:25 Comment(0)
A
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.

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>
Aret answered 18/11, 2015 at 18:35 Comment(0)
P
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/

Persiflage answered 2/2, 2013 at 2:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.