Create a gist now

Instantly share code, notes, and snippets.

@Mte90 /ffos-check
Last active Aug 24, 2016

Check Firefox OS version
function getVersion() {
if (navigator.userAgent.match(/(mobile|tablet)/i)) {
var ffVersionArray = (navigator.userAgent.match(/Firefox\/([\d]+\.[\w]?\.?[\w]+)/));
if (ffVersionArray.length === 2) {
//Check with the gecko version the Firefox OS version
//Table https://developer.mozilla.org/en-US/docs/Gecko_user_agent_string_reference
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 = ffVersionArray[1];
var sStr = ffVersionArray[1].substring(0, 4);
if (hashVersion[sStr]) {
rver = hashVersion[sStr];
}
return rver;
}
}
return (null);
}
//Return the version of Firefox OS or null if not Firefox OS
//The simulator use the gecko version of the browser!
@joshua-s

Firefox OS 1.5 does not exist. It has become 2.0.

@bryanjhv

As it was said, Firefox OS 1.5 never existed, and new versions are not covered.

Following code snippet should fix that.

// Taken from https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/User-Agent/Firefox#Firefox_OS_version_number
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': '2.0',
  '34.0': '2.1',
  '37': '2.2',
  '44': '2.5'
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment