Search code examples
javascriptfirefox-os

Check Firefox OS version


I'm working on a snippet for check the Firefox OS version used.

Now i'm using the gecko version in the user agent string (is different in every version of Firefox OS) but it's not a professional solution often is simple.

The gist: https://gist.github.com/Mte90/11087561

Any suggestion?

The gist is updated with the better solution for check the Firefox OS version


Solution

  • Not very nice way to do this but you could parse the user agent

     function convertVersionNumber(ver) {
         var hashVersion = {
             '18.0': '1.0.1',
             '18.1': '1.1',
             '26.0': '1.2',
             '28.0': '1.3',
             '30.0': '1.4',
             '32.0': '1.5'
         }
         var rver = ver;
         var sStr = ver.substring(0, 4);
         if (hashVersion[sStr]) {
             rver = hashVersion[sStr];
         }
         return (rver);
    
     } function getVersion() {
         if (navigator.userAgent.match(/(mobile|tablet)/i)) {
             var ffVersionArray = (navigator.userAgent.match(/Firefox\/([\d]+\.[\w]?\.?[\w]+)/));
             if (ffVersionArray.length === 2) {
                 return (convertVersionNumber(ffVersionArray[1]));
             }
         }
         return (null); 
    }