broswer.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. function versions() {
  2. var u = window.navigator.userAgent;
  3. var uLowCase = u.toLowerCase();
  4. return {
  5. userAgent: u,
  6. // IE内核
  7. trident: u.indexOf("Trident") > -1,
  8. // opera内核
  9. presto: u.indexOf("Presto") > -1,
  10. // 苹果、谷歌内核
  11. webKit: u.indexOf("AppleWebKit") > -1,
  12. // 火狐内核
  13. gecko: u.indexOf("Gecko") > -1 && u.indexOf("KHTML") === -1,
  14. // 是否为移动终端 / Tablets use desktop version
  15. mobile:
  16. /Android|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent) &&
  17. !/Tablet|iPad/i.test(navigator.userAgent),
  18. // ios终端
  19. ios: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/),
  20. // android终端或者uc浏览器
  21. android: u.indexOf("Android") > -1 || u.indexOf("Linux") > -1,
  22. // 是否为iPhone或者安卓QQ浏览器
  23. iPhone: u.indexOf("iPhone") > -1 || u.indexOf("Mac") > -1,
  24. // 是否为iPad
  25. iPad: u.indexOf("iPad") > -1,
  26. // 是否为web应用程序,没有头部与底部
  27. webApp: u.indexOf("Safari") === -1,
  28. // 是否为微信浏览器
  29. weixin: ~u.indexOf("MicroMessenger"),
  30. // 火狐内核版本
  31. firefoxCore: uLowCase.match(/firefox\/([\d.]+)/),
  32. // chrome内核版本
  33. chromeCore: uLowCase.match(/chrome\/([\d.]+)/),
  34. // webkit内核版本
  35. webkitCore: uLowCase.match(/applewebkit\/([\d.]+)/),
  36. getURLParam: function (key) {
  37. let querys = window.location.search.substring(1).split("&");
  38. for (let i = 0; i < querys.length; i++) {
  39. let keypair = querys[i].split("=");
  40. if (keypair.length === 2 && keypair[0] === key) {
  41. return keypair[1];
  42. }
  43. }
  44. return "";
  45. },
  46. };
  47. }
  48. export default versions();