How can I detect kindle fire with javascript?

10,203

Solution 1

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

Solution 2

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
}

Solution 3

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

Solution 4

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>
Share:
10,203
gabitzish
Author by

gabitzish

Updated on June 21, 2022

Comments

  • gabitzish
    gabitzish about 2 years

    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?

  • Aaron
    Aaron almost 12 years
    Awesome. Can you provide a reg ex that will work as Kindle updates to newer versions?
  • Yaakov
    Yaakov about 11 years
    Thanks for the perfect reference link.
  • Andrew Childs
    Andrew Childs almost 11 years
    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/…
  • ecraig12345
    ecraig12345 almost 9 years
    Condensed version (and updated to include current Kindles as of this comment date): /Kindle|Silk|KFAPW|KFARWI|KFASWI|KFFOWI|KFJW|KFMEWI|KFOT|KFS‌​AW|KFSOWI|KFTBW|KFTH‌​W|KFTT|WFFOWI/i.test‌​(ua)