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?

gabitzish
  • 9,535
  • 7
  • 44
  • 65

5 Answers5

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
}
Venkat Reddy
  • 1,046
  • 1
  • 8
  • 13
  • 4
    Condensed version (and updated to include [current Kindles](https://developer.amazon.com/appsandservices/solutions/devices/kindle-fire/specifications/01-device-and-feature-specifications) as of this comment date): `/Kindle|Silk|KFAPW|KFARWI|KFASWI|KFFOWI|KFJW|KFMEWI|KFOT|KFSAW|KFSOWI|KFTBW|KFTHW|KFTT|WFFOWI/i.test(ua)` – ecraig12345 Sep 17 '15 at 21:01
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

Offbeatmammal
  • 7,970
  • 2
  • 33
  • 52
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
MMM
  • 7,221
  • 2
  • 24
  • 42
  • Awesome. Can you provide a reg ex that will work as Kindle updates to newer versions? – Aaron Aug 14 '12 at 21:20
  • 5
    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: https://developer.amazon.com/sdk/fire/specifications.html#UserAgentStrings – Andrew Childs Sep 06 '13 at 15:49
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>
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/

Rohit
  • 7,449
  • 9
  • 45
  • 55