租房小程序前端代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

211 lines
6.4 KiB

3 months ago
  1. ## Bowser
  2. A Browser detector. Because sometimes, there is no other way, and not even good modern browsers always provide good feature detection mechanisms.
  3. [![Build Status](https://travis-ci.org/lancedikson/bowser.svg?branch=master)](https://travis-ci.org/lancedikson/bowser)
  4. So... it works like this:
  5. ``` js
  6. if (bowser.msie && bowser.version <= 6) {
  7. alert('Hello China');
  8. }
  9. ```
  10. ## 1.1.0 breaking changes
  11. We don't save built script in the repo anymore. The main file (`src/bowser.js`) is available through NPM or Bower.
  12. Also you can download minified file from [the release page](https://github.com/ded/bowser/releases).
  13. ## 1.0.0 breaking changes
  14. `browser = require('bowser').browser;` becomes `bowser = require('bowser');`
  15. ---
  16. ## API
  17. ### bowser`:Object`
  18. Use it to get object with detected flags of your current browser.
  19. ### bowser._detect(ua `:String`)`:Object`
  20. Use it to get object with detected flags from User Agent string.
  21. ### bowser.check(minVersions`:Object`, strictMode`:Boolean`, [ua]`:String`)`:Boolean`
  22. Use it to check if browser is supported. In default non-strict mode any browser family not present in `minVersions` will pass the check (like Chrome in the third call in the sample bellow). When strict mode is enabled then any not specified browser family in `minVersions` will cause `check` to return `false` (in the sample it is the fourth call, the last one).
  23. ``` js
  24. /**
  25. * in case of using IE10
  26. */
  27. bowser.check({msie: "11"}); // true
  28. bowser.check({msie: "9.0"}); // false
  29. /**
  30. * specific user agent
  31. */
  32. bowser.check({chrome: "45"}, window.navigator.userAgent); // true
  33. /**
  34. * but false in strict mode
  35. */
  36. bowser.check({chrome: "45"}, true, window.navigator.userAgent); // false
  37. ```
  38. ### bowser.compareVersions(versions`:Array<String>`)`:Number`
  39. Use it to compare two versions.
  40. ``` js
  41. bowser.compareVersions(['9.0', '10']);
  42. // -1
  43. ```
  44. ### bowser.isUnsupportedBrowser(minVersions`:Object`, [strictMode]`:Boolean`, [ua]`:string`)`:Boolean`
  45. Use it to check if browser is unsupported.
  46. ``` js
  47. bowser.isUnsupportedBrowser({msie: "10"}, window.navigator.userAgent);
  48. // true / false
  49. ```
  50. See more examples in [tests](test/test.js).
  51. ---
  52. ## Bowser Flags
  53. Your mileage may vary, but these flags should be set. See Contributing below.
  54. ``` js
  55. alert('Hello ' + bowser.name + ' ' + bowser.version);
  56. ```
  57. ### All detected browsers
  58. These flags are set for all detected browsers:
  59. * `name` - A human readable name for this browser. E.g. 'Chrome', ''
  60. * `version` - Version number for the browser. E.g. '32.0'
  61. For unknown browsers, Bowser makes a best guess from the UA string. So, these may not be set.
  62. ### Rendering engine flags
  63. If detected, one of these flags may be set to true:
  64. * `webkit` - Chrome 0-27, Android <4.4, iOs, BB, etc.
  65. * `blink` - Chrome >=28, Android >=4.4, Opera, etc.
  66. * `gecko` - Firefox, etc.
  67. * `msie` - IE <= 11
  68. * `msedge` - IE > 11
  69. Safari, Chrome and some other minor browsers will report that they have `webkit` engines.
  70. Firefox and Seamonkey will report that they have `gecko` engines.
  71. ``` js
  72. if (bowser.webkit) {
  73. // do stuff with safari & chrome & opera & android & blackberry & webos & silk
  74. }
  75. ```
  76. ### Device flags
  77. If detected, one of these flags may be set to true:
  78. * `mobile` - All detected mobile OSes are additionally flagged `mobile`, **unless it's a tablet**
  79. * `tablet` - If a tablet device is detected, the flag `tablet` is **set instead of `mobile`**.
  80. ### Browser flags
  81. If detected, one of these flags may be set to true. The rendering engine flag is shown in []'s:
  82. * `chrome` - [`webkit`|`blink`]
  83. * `chromium` - [`webkit`|`blink`]
  84. * `firefox` - [`gecko`]
  85. * `msie`
  86. * `msedge`
  87. * `safari` - [`webkit`]
  88. * `android` - native browser - [`webkit`|`blink`]
  89. * `ios` - native browser - [`webkit`]
  90. * `opera` - [`blink` if >=15]
  91. * `samsungBrowser` - [`blink`]
  92. * `phantom` - [`webkit`]
  93. * `blackberry` - native browser - [`webkit`]
  94. * `webos` - native browser - [`webkit`]
  95. * `silk` - Amazon Kindle browser - [`webkit`]
  96. * `bada` - [`webkit`]
  97. * `tizen` - [`webkit`]
  98. * `seamonkey` - [`gecko`]
  99. * `sailfish` - [`gecko`]
  100. * `ucbrowser` — [`webkit`]
  101. * `qupzilla` — [`webkit`]
  102. * `vivaldi` — [`blink`]
  103. * `sleipnir` — [`blink`]
  104. * `kMeleon` — [`gecko`]
  105. * `whale` — [`blink`]
  106. For all detected browsers the browser version is set in the `version` field.
  107. ### OS Flags
  108. If detected, one of these flags may be set to true:
  109. * `mac`
  110. * `windows` - other than Windows Phone
  111. * `windowsphone`
  112. * `linux` - other than `android`, `chromeos`, `webos`, `tizen`, and `sailfish`
  113. * `chromeos`
  114. * `android`
  115. * `ios` - also sets one of `iphone`/`ipad`/`ipod`
  116. * `blackberry`
  117. * `firefoxos`
  118. * `webos` - may also set `touchpad`
  119. * `bada`
  120. * `tizen`
  121. * `sailfish`
  122. `osname` and `osversion` may also be set:
  123. * `osname` - for the OS flags detected above: macOS, Windows, Windows Phone, Linux, Chrome OS, Android, iOS, Blackberry OS, Firefox OS, WebOS, Bada, Tizen, Sailfish OS, and Xbox
  124. * `osversion` - for Android, iOS, MacOS, Windows, Windows Phone, WebOS, Bada, and Tizen. If included in UA string.
  125. iOS is always reported as `ios` and additionally as `iphone`/`ipad`/`ipod`, whichever one matches best.
  126. If WebOS device is an HP TouchPad the flag `touchpad` is additionally set.
  127. ### Browser capability grading
  128. One of these flags may be set:
  129. * `a` - This browser has full capabilities
  130. * `c` - This browser has degraded capabilities. Serve simpler version
  131. * `x` - This browser has minimal capabilities and is probably not well detected.
  132. There is no `b`. For unknown browsers, none of these flags may be set.
  133. ### Ender Support
  134. `package.json`
  135. ``` json
  136. "dependencies": {
  137. "bowser": "x.x.x"
  138. }
  139. ```
  140. ``` js
  141. if (require('bowser').chrome) {
  142. alert('Hello Silicon Valley')
  143. }
  144. ```
  145. ### Contributing
  146. If you'd like to contribute a change to bowser, modify the files in `src/`, then run the following (you'll need node + npm installed):
  147. ``` sh
  148. $ npm install
  149. $ make test
  150. ```
  151. Please do not check-in the built files `bowser.js` and `bowser.min.js` in pull requests.
  152. ### Adding tests
  153. See the list in `src/useragents.js` with example user agents and their expected bowser object.
  154. Whenever you add support for new browsers or notice a bug / mismatch, please update the list and
  155. check if all tests are still passing.
  156. ### Similar Projects
  157. * [Kong](https://github.com/BigBadBleuCheese/Kong) - A C# port of Bowser.
  158. ### License
  159. Licensed as MIT. All rights not explicitly granted in the MIT license are reserved. See the included LICENSE file for more details.