Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var Utils, browser, os, ua;
- Utils = {
- regexp: {
- UAChrome: /(chrome)[ Chrome\/]([\w.]+)?/,
- UAwebkit: /(safari)[ \/]([\w.]+)/,
- UAopera: /(opera)(?:.*version)?[ \/]([\w.]+)/,
- UAmsie: /(ie) ([\w.]+)/,
- UAmozilla: /(firefox)(?:.*? rv:([\w.]+))?/,
- OSwindows: /(windows)/,
- OSmac: /(macintosh)/,
- OSlinux: /(linux)/,
- OSiOS: /(iphone)/,
- OSiPad: /(ipad)/,
- OSandroid: /(android)/
- },
- uaMatch: function(ua) {
- var match;
- if (typeof ua === 'undefined') {
- return {
- browser: '',
- version: ''
- };
- }
- ua = ua.toLowerCase();
- match = this.regexp.UAChrome.exec(ua) || this.regexp.UAwebkit.exec(ua) || this.regexp.UAopera.exec(ua) || this.regexp.UAmsie.exec(ua) || ua.indexOf("compatible") < 0 && this.regexp.UAmozilla.exec(ua) || [];
- return {
- browser: match[1] || '',
- version: match[2] || ''
- };
- },
- osMatch: function(ua) {
- var match;
- if (typeof ua === 'undefined') {
- return {
- os: ''
- };
- }
- ua = ua.toLowerCase();
- match = this.regexp.OSwindows.exec(ua) || this.regexp.OSmac.exec(ua) || this.regexp.OSandroid.exec(ua) || this.regexp.OSlinux.exec(ua) || this.regexp.OSiOS.exec(ua) || this.regexp.OSiPad.exec(ua) || [];
- return {
- os: match[1]
- };
- }
- };
- browser = "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.104 Safari/537.36 LiveChatSmartClient/8.1.12.0";
- os = Utils.osMatch(browser);
- console.log(os);
- ua = Utils.uaMatch(browser);
- console.log(ua);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement