UA determines the environment in which the page is opened, and then writes the callback function in the context of the callback

Source: Internet
Author: User

  1. (function () {
  2. /*
  3. * How to use:
  4. * I. INTRODUCTION of Ua.js
  5. * Second, directly invoke the properties and methods of the Mobileport object.
  6. *
  7. * Mobileport Object
  8. * Attributes: mobileport.back;//array contents are as follows
  9. * Method: Mobileport.androidbrowser (callBack) Android Browser//callback callback is only performed under Android browser
  10. * Method: Mobileport.iosbrowser (callBack) iOS browser///below all similar
  11. * Method: Mobileport.qqbrowser (callBack) QQ Browser
  12. * Method: Mobileport.ucbrowser (callBack) UC Browser
  13. * Method: Mobileport.wxbrowser (callBack) browser
  14. * Method: Mobileport.pc (callBack) PC browser
  15. * Method: Mobileport.move (callBack) Mobile browser
  16. * Method: Mobileport.androidapp (callBack, parameter) Android app
  17. * Method: Mobileport.iosapp (callBack, parameter) IOS app
  18. *
  19. * CallBack is a callback function that executes in a specified environment.
  20. * parameter is a parameter on the URL that identifies the app with browser (must), the string.
  21. * For example Www.baidu.com?from=app parameter refers to From=app
  22. * From=app is the Web page that the front and back end has agreed on to refer to the app request.
  23. *
  24. * Possible values in the back array: kernel, browser, mobile platform, PC-side platform, other
  25. * WebKit Trident Presto Gecko//kernel WebKit kernel Trident kernel Presto kernel Gecko kernel
  26. * IE Chrome Firefox opera safari//browser IE browser Chrome browser Firefox browser Opera browser Safari browser
  27. * Ucbrowser Mqqbrowser//Browser UC Browser QQ browser
  28. * Android ipad iphone//Mobile platform Android platform ipad platform iphone platform
  29. * Mac Windows Linux//PC-side platform Mac platform Windows platform Linux platform
  30. * Move WX//Other move mobile side platform WX Browser
  31. */

  1. /*
  2. * Regular Assignment kernel
  3. */
  4. WebKit kernel
  5. var webkit =/webkit/i;
  6. IE kernel
  7. var Trident =/trident/i;
  8. Opera kernel
  9. var Presto =/presto/i;
  10. Firefox kernel
  11. var Gecko =/gecko/i;
  12. /*
  13. * Regular Assignment browser
  14. */
  15. Chrome
  16. var chrome1 =/chrome\/(\d+\.\d+)/I;
  17. Firefox browser
  18. var Firefox =/firefox\/(\d+\.\d+)/I;
  19. Opera browser
  20. var opera =/opera (\/|) (\d+ (\.\d+)?) (.+? (version\/(\d+ (\.\d+)))? /I;
  21. Safari browser
  22. var safari =/(\d+\.\d)? (?:\. \d)? \s+safari\/? (\d+\.\d+)?/I;
  23. Internet explorer
  24. var IE =/msie (\d+\.\d+)/I;
  25. UC Browser
  26. var ucbrowser =/ucbrowser/i;
  27. QQ Browser
  28. var mqqbrowser =/mqqbrowser/i;
  29. /*
  30. * Regular assignment PC side
  31. */
  32. Macintosh System
  33. var Mac =/macintosh/i;
  34. Windows platform
  35. var windows =/windows/i;
  36. Linux platforms
  37. var Linux =/linux/i;
  38. /*
  39. * Regular Assignment Mobile end
  40. */
  41. Android system
  42. var android =/android/i;
  43. ipad system
  44. var ipad =/ipad/i;
  45. iphone system
  46. var iphone =/iphone/i;
  47. /*
  48. * Regular Assignment other
  49. */
  50. Mobile Terminal
  51. var move =
  52. /(nokia|iphone|android|ipad|motorola|^mot\-|softbank|foma|docomo|kddi|up\.browser|up\.link|htc|dopod|blazer| netfront|helio|hosin|huawei|novarra| coolpad|webos|techfaith|palmsource|blackberry|alcatel|amoi|ktouch|nexian|samsung|^sam\-|s[cg]h|^lge|ericsson| Philips|sagem|wellcom|bunjalloo|maui|symbian|smartphone|midp|wap|phone|windows ce|iemobile|^spice|^bird|^zte\-| Longcos|pantech|gionee|^sie\-|portalmmm|jig\s browser|hiptop|^ucweb|^benq|haier|^lct|opera\s*mobi|opera\*mini| 320x320|240x320|176x220)/I;
  53. Open it
  54. var wx =/micromessenger/i;
  55. var back = [];
  56. var ua = navigator.useragent;
  57. Kernel judgment
  58. if (Webkit.test (UA)) {//webkit
  59. Back.push ("WebKit");
  60. };
  61. if (Trident.test (UA)) {//ie
  62. Back.push ("Trident");
  63. };
  64. if (Presto.test (UA)) {//Open gate
  65. Back.push ("Presto");
  66. };
  67. if (Gecko.test (UA)) {//Firefox
  68. Back.push ("Gecko");
  69. };
  70. Browser judgment
  71. if (Ie.test (UA)) {
  72. Back.push ("IE");
  73. };
  74. if (Chrome1.test (UA)) {
  75. Back.push ("Chrome");
  76. };
  77. if (Firefox.test (UA)) {
  78. Back.push ("Firefox");
  79. };
  80. if (Opera.test (UA)) {
  81. Back.push ("opera");
  82. };
  83. if (Safari.test (UA)) {
  84. Back.push ("Safari");
  85. };
  86. if (Ucbrowser.test (UA)) {
  87. Back.push ("Ucbrowser");
  88. };
  89. if (Mqqbrowser.test (UA)) {
  90. Back.push ("Mqqbrowser");
  91. };
  92. PC Platform judgment
  93. if (Mac.test (UA)) {
  94. Back.push ("Mac");
  95. };
  96. if (Windows.test (UA)) {
  97. Back.push ("Windows");
  98. };
  99. if (Linux.test (UA)) {
  100. Back.push ("Linux");
  101. };
  102. Mobile Platform Judgment
  103. if (Android.test (UA)) {
  104. Back.push ("Android");
  105. };
  106. if (Ipad.test (UA)) {
  107. Back.push ("ipad");
  108. };
  109. if (Iphone.test (UA)) {
  110. Back.push ("iphone");
  111. };
  112. Other
  113. if (Move.test (UA)) {
  114. Back.push ("move");
  115. };
  116. if (Wx.test (UA)) {
  117. Back.push ("WX");
  118. };
  119. Mobileport = {};
  120. Back contains all the information
  121. Mobileport.back = back;
  122. Android Browser
  123. Mobileport.androidbrowser = function (callBack) {
  124. if (Android.test (UA)) {
  125. CallBack ();
  126. } else {
  127. return "error";
  128. }
  129. };
  130. iOS browser
  131. Mobileport.iosbrowser = function (callBack) {
  132. if (Ipad.test (UA) | | iphone.test (UA)) {
  133. CallBack ();
  134. } else {
  135. return "error";
  136. }
  137. };
  138. QQ Browser
  139. Mobileport.qqbrowser = function (callBack) {
  140. if (Mqqbrowser.test (UA)) {
  141. CallBack ();
  142. } else {
  143. return "error";
  144. }
  145. };
  146. UC Browser
  147. Mobileport.ucbrowser = function (callBack) {
  148. if (Ucbrowser.test (UA)) {
  149. CallBack ();
  150. } else {
  151. return "error";
  152. }
  153. };
  154. Open it
  155. Mobileport.wxbrowser = function (callBack) {
  156. if (Wx.test (UA)) {
  157. CallBack ();
  158. } else {
  159. return "error";
  160. }
  161. };
  162. Androidapp
  163. Mobileport.androidapp = function (callBack, parameter) {
  164. var ourl = Location.search;
  165. var tc = new RegExp (parameter);
  166. if (Android.test (UA) && tc.test (Ourl)) {
  167. CallBack ();
  168. } else {
  169. return "error";
  170. }
  171. };
  172. Iosapp
  173. Mobileport.iosapp = function (callBack, parameter) {
  174. var ourl = Location.search;
  175. var tc = new RegExp (parameter);
  176. if ((Ipad.test (UA) | | iphone.test (UA)) && Tc.test (Ourl)) {
  177. CallBack ();
  178. } else {
  179. return "error";
  180. }
  181. };
  182. PC Platform
  183. mobileport.pc = function (callBack) {
  184. if (Linux.test (UA) | | | windows.test (UA) | | Mac.test (UA)) {
  185. CallBack ();
  186. } else {
  187. return "error";
  188. }
  189. }
  190. Mobile platform
  191. Mobileport.move = function (callBack) {
  192. if (Move.test (UA)) {
  193. CallBack ();
  194. } else {
  195. return "error";
  196. }
  197. }
  198. })();

UA determines the environment in which the page is opened, and then writes the callback function in the context of the callback

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.