1. /**
    2. * 判断终端以及浏览器
    3. * userAgent string User-Agent信息
    4. */
    5. function judgeTerminalBrowser (userAgent) {
    6. let data = {
    7. terminal: undefined,
    8. browser: undefined
    9. };
    10. let regs = {};
    11. let terminal = {
    12. 'windows nt 10' : 'Windows 10',
    13. 'windows nt 6.3' : 'Windows 8.1',
    14. 'windows nt 6.2' : 'Windows 8',
    15. 'windows nt 6.1' : 'Windows 7',
    16. 'windows nt 6.0' : 'Windows Vista',
    17. 'windows nt 5.2' : 'Windows Server 2003XP x64',
    18. 'windows nt 5.1' : 'Windows XP',
    19. 'windows xp' : 'Windows XP',
    20. 'windows nt 5.0' : 'Windows 2000',
    21. 'windows me' : 'Windows ME',
    22. 'win98' : 'Windows 98',
    23. 'win95' : 'Windows 95',
    24. 'win16' : 'Windows 3.11',
    25. 'macintosh|mac os x' : 'Mac OS X',
    26. 'mac_powerpc' : 'Mac OS 9',
    27. 'linux' : 'Linux',
    28. 'ubuntu' : 'Ubuntu',
    29. 'phone' : 'iPhone',
    30. 'pod' : 'iPod',
    31. 'pad' : 'iPad',
    32. 'android' : 'Android',
    33. 'blackberry' : 'BlackBerry',
    34. 'webos' : 'Mobile',
    35. 'freebsd' : 'FreeBSD',
    36. 'sunos' : 'Solaris'
    37. };
    38. for (let key in terminal) {
    39. if (new RegExp(key).test(userAgent.toLowerCase())) {
    40. data.terminal = terminal[key];
    41. break;
    42. }
    43. }
    44. if (regs = userAgent.match(/MSIE\s(\d+)\..*/)) {
    45. // ie 除11
    46. data.browser = 'ie ' + regs['1'];
    47. } else if (regs = userAgent.match(/FireFox\/(\d+)\..*/)) {
    48. data.browser = 'firefox ' + regs['1'];
    49. } else if (regs = userAgent.match(/Opera[\s|\/](\d+)\..*/)) {
    50. data.browser = 'opera ' + regs['1'];
    51. } else if (regs = userAgent.match(/Chrome\/(\d+)\..*/)) {
    52. data.browser = 'chrome ' + regs['1'];
    53. } else if (regs = userAgent.match(/Safari\/(\d+)\..*$/)) {
    54. // chrome浏览器都声明了safari
    55. data.browser = 'safari ' + regs['1'];
    56. } else if (regs = userAgent.match(/rv:(\d+)\..*/)) {
    57. // ie 11
    58. data.browser = 'ie ' + regs['1'];
    59. }
    60. return data;
    61. }