Skip to content

Instantly share code, notes, and snippets.

@WebReflection
Last active December 26, 2015 06:29
Show Gist options
  • Save WebReflection/7107617 to your computer and use it in GitHub Desktop.
Save WebReflection/7107617 to your computer and use it in GitHub Desktop.
navigator.version (major, minor, revision) where exposed and possibl updated to be as cross browser as possible
/** Andrea Giammarchi
* WTFPL - http://www.wtfpl.net/
*/
'version' in navigator || (
navigator.version =
/(?:(?:OS(?: X)?|Android|Windows(?: NT)) |(?:IEMobile|Version|webOS|Nokia\w+)\/)(\d+)[_.](\d+)(?:[_.](\d+(?:\.\d+)?))?/
.test(navigator.userAgent) ?
{
major: RegExp.$1,
minor: RegExp.$2 || '0',
// let me introduce you BB10 versioning ...
revision: (RegExp.$3 || '0').replace(/^0\./, ''),
// compare with coercion
// if (os.version == 7) {}
// NOTE: the == instead of ===
// works with other operators too
// such os.version < 7 etc
valueOf: function () {
return this.major;
}
} :
{} // unknown (some browser deos not expose the OS)
);
@WebReflection
Copy link
Author

that's about the WTFPL :) Thanks.
P.S. yes, 10.9 makes sense, I haven't updated to that and I am on 10.8.5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment