browser.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. // function versions() {
  2. // var u = window.navigator.userAgent;
  3. // return {
  4. // // IE内核
  5. // trident: u.indexOf("Trident") > -1,
  6. // // Firefox
  7. // firefox: u.indexOf("Firefox") > -1,
  8. // // edge
  9. // edge: u.indexOf("Edge") > -1,
  10. // // opera内核
  11. // presto: u.indexOf("Presto") > -1,
  12. // // 苹果、谷歌内核
  13. // webKit: u.indexOf("AppleWebKit") > -1,
  14. // // 火狐内核
  15. // gecko: u.indexOf("Gecko") > -1 && u.indexOf("KHTML") === -1,
  16. // // 是否为移动终端
  17. // mobile: /Android|webOS|iPhone|iPod|BlackBerry/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. // language: (navigator.browserLanguage || navigator.language).toLowerCase(),
  32. // };
  33. // }
  34. // export default versions();
  35. export default {
  36. hasURLParam: 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[0] == key) {
  41. return true;
  42. }
  43. }
  44. return false;
  45. },
  46. getLang() {
  47. return this.getURLParam("lang") || "zh";
  48. },
  49. getURLParam: function (key) {
  50. let querys = window.location.search.substring(1).split("&");
  51. for (let i = 0; i < querys.length; i++) {
  52. let keypair = querys[i].split("=");
  53. if (keypair.length === 2 && keypair[0] === key) {
  54. try {
  55. return decodeURIComponent(keypair[1]);
  56. } catch (error) {
  57. return keypair[1];
  58. }
  59. }
  60. }
  61. return "";
  62. },
  63. valueFromUrl(key) {
  64. return this.urlHasValue(key, true);
  65. },
  66. urlHasValue: function (key, isGetValue) {
  67. if (
  68. key === "m" &&
  69. window.__ProjectNum &&
  70. window.__ProjectNum != "__ProjectNum__"
  71. ) {
  72. return window.__ProjectNum;
  73. }
  74. let querys = window.location.search.substr(1).split("&");
  75. if (isGetValue) {
  76. for (let i = 0; i < querys.length; i++) {
  77. let keypair = querys[i].split("=");
  78. if (keypair.length === 2 && keypair[0] === key) {
  79. return keypair[1];
  80. }
  81. }
  82. return "";
  83. } else {
  84. //return window.location.search.match("&" + key + "|\\?" + key) != null 有bug
  85. for (let i = 0; i < querys.length; i++) {
  86. let keypair = querys[i].split("=");
  87. if (keypair[0] == key) {
  88. return true;
  89. }
  90. }
  91. return false;
  92. }
  93. },
  94. detectWeixin: function () {
  95. //微信 包括PC的微信
  96. return (
  97. window.navigator.userAgent.toLowerCase().match(/MicroMessenger/i) ==
  98. "micromessenger"
  99. );
  100. },
  101. detectWeixinMiniProgram: function () {
  102. return window.navigator.userAgent.match("miniProgram");
  103. },
  104. detectIOS: function () {
  105. return this.detectIPhone() || this.detectIPad() || this.detectIPod();
  106. },
  107. detectIPhone: function () {
  108. var e = window.navigator.userAgent,
  109. t = /iPhone/;
  110. return t.test(e);
  111. },
  112. detectIPad: function () {
  113. if (
  114. window.navigator.platform === "MacIntel" &&
  115. window.navigator.maxTouchPoints > 1
  116. ) {
  117. return true;
  118. }
  119. var e = window.navigator.userAgent,
  120. t = /iPad/;
  121. return t.test(e);
  122. },
  123. detectIPod: function () {
  124. var e = window.navigator.userAgent,
  125. t = /iPod/;
  126. return t.test(e);
  127. },
  128. detectAndroid: function () {
  129. var e = window.navigator.userAgent;
  130. return e.indexOf("Android") !== -1;
  131. },
  132. detectIE: function () {
  133. var e = window.navigator.userAgent,
  134. t = e.indexOf("MSIE ");
  135. return t !== -1 || !!navigator.userAgent.match(/Trident.*rv\:11\./);
  136. },
  137. detectOpera: function () {
  138. var e = window.navigator.userAgent;
  139. return e.indexOf("OPR") !== -1;
  140. },
  141. detectSafari: function () {
  142. var e = window.navigator.userAgent,
  143. t = e.indexOf("Safari");
  144. return t !== -1 && !this.detectOpera() && !this.detectChrome(); //xzw add detectOpera
  145. },
  146. detectFirefox: function () {
  147. var e = window.navigator.userAgent;
  148. return e.indexOf("Firefox") !== -1;
  149. },
  150. detectChrome: function () {
  151. var e = window.navigator.userAgent;
  152. return e.indexOf("Chrome") !== -1 && !this.detectOpera();
  153. },
  154. detectAndroidMobile: function () {
  155. var e = window.navigator.userAgent;
  156. return this.detectAndroid() && e.indexOf("Mobile") !== -1;
  157. },
  158. };