JSFiddle - React, Tailwind, and code Playground
JavaScript
// Override the user agent so that you can see it work!
navigator.__defineGetter__('userAgent', function(){
return 'Mozilla/5.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; InfoPath.2; SLCC1; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; .NET CLR 2.0.50727)';
});
// The code - first bit is all the UserAgent library.
(function(wndw) {
var Browsers, OS, Platform, Versions, browser_name, browser_version, os, platform;
Versions = {
Firefox: /firefox\/([\d\w\.\-]+)/i,
IE: /msie\s([\d\.]+[\d])/i,
Chrome: /chrome\/([\d\w\.\-]+)/i,
Safari: /version\/([\d\w\.\-]+)/i,
Ps3: /([\d\w\.\-]+)\)\s*$/i,
Psp: /([\d\w\.\-]+)\)?\s*$/i
};
Browsers = {
Konqueror: /konqueror/i,
Chrome: /chrome/i,
Safari: /safari/i,
IE: /msie/i,
Opera: /opera/i,
PS3: /playstation 3/i,
PSP: /playstation portable/i,
Firefox: /firefox/i
};
OS = {
WindowsVista: /windows nt 6\.0/i,
Windows7: /windows nt 6\.\d+/i,
Windows2003: /windows nt 5\.2/i,
WindowsXP: /windows nt 5\.1/i,
Windows2000: /windows nt 5\.0/i,
OSX: /os x (\d+)[._](\d+)/i,
Linux: /linux/i,
Wii: /wii/i,
PS3: /playstation 3/i,
PSP: /playstation portable/i,
Ipad: /\(iPad.*os (\d+)[._](\d+)/i,
Iphone: /\(iPhone.*os (\d+)[._](\d+)/i
};
Platform = {
Windows: /windows/i,
Mac: /macintosh/i,
Linux: /linux/i,
Wii: /wii/i,
Playstation: /playstation/i,
Ipad: /ipad/i,
Ipod: /ipod/i,
Iphone: /iphone/i,
Android: /android/i,
Blackberry: /blackberry/i
};
function UserAgent(source) {
if (source == null) {
source = navigator.userAgent;
}
this.source = source.replace(/^\s*/, '').replace(/\s*$/, '');
this.browser_name = browser_name(this.source);
this.browser_version = browser_version(this.source);
this.os = os(this.source);
this.platform = platform(this.source);
}
browser_name = function(string) {
if (Browsers.Konqueror.test(string)) {
return...