Guest User

Untitled

a guest
Jul 19th, 2018
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.86 KB | None | 0 0
  1. var browserVersion = int((/msie (d+)/.exec(lowercase(navigator.userAgent)) || [])[1]);
  2.  
  3. app.service('browser', ['$window', function($window) {
  4.  
  5. return function() {
  6.  
  7. var userAgent = $window.navigator.userAgent;
  8.  
  9. var browsers = {chrome: /chrome/i, safari: /safari/i, firefox: /firefox/i, ie: /internet explorer/i};
  10.  
  11. for(var key in browsers) {
  12. if (browsers[key].test(userAgent)) {
  13. return key;
  14. }
  15. };
  16.  
  17. return 'unknown';
  18. }
  19.  
  20. }]);
  21.  
  22. angular.module('yourModule').value('bowser', bowser);
  23.  
  24. detectFactory.$inject = ['$window'];
  25. function detectFactory($window) {
  26. return detect.parse($window.navigator.userAgent);
  27. }
  28. angular.module('yourModule').factory('detect', detectFactory);
  29.  
  30. function someLibFactory() {
  31. return new SomeLib();
  32. }
  33. angular.module('yourModule').factory('someLib', someLibFactory);
  34.  
  35. BrowserAdapter.$inject = ['bowser']; // bring in lib
  36. function BrowserAdapter(bowser) {
  37. this.bowser = bowser;
  38. }
  39.  
  40. BrowserAdapter.prototype.isIe9 = function() {
  41. return this.bowser.msie && this.browser.version == 9;
  42. }
  43.  
  44. angular.module('yourModule').service('browserAdapter', BrowserAdapter);
  45.  
  46. angular.module('app').value('isIe9', broswerAdapter.isIe9);
  47.  
  48. /**
  49. * documentMode is an IE-only property
  50. * http://msdn.microsoft.com/en-us/library/ie/cc196988(v=vs.85).aspx
  51. */
  52. var msie = document.documentMode;
  53.  
  54. // var msie = document.documentMode;
  55. var msie = $document[0].documentMode;
  56. // if is IE (documentMode contains IE version)
  57. if (msie) {
  58. // IE logic here
  59.  
  60. if (msie === 9) {
  61. // IE 9 logic here
  62.  
  63. }
  64. }
  65.  
  66. <!--[if IE 9]>
  67. <script type="text/javascript">
  68. window.isIE9 = true;
  69. </script>
  70. <![endif]-->
  71.  
  72. //Detect if IE 9
  73. if(navigator.appVersion.indexOf("MSIE 9.")!=-1)
  74.  
  75. var app = angular.module('myapp', ["ng.deviceDetector"]);
  76. app.controller('DeviceCtrl', ["$scope","deviceDetector",function($scope,deviceDetector) {
  77. console.log("browser: ", deviceDetector.browser);
  78. console.log("browser version: ", deviceDetector.browser_version);
  79. console.log("device: ", deviceDetector.device);
  80. }]);
  81.  
  82. (function(window, angular, undefined) {'use strict';
  83. var agl = angular || {};
  84. var ua = navigator.userAgent;
  85.  
  86. agl.ISFF = ua.indexOf('Firefox') != -1;
  87. agl.ISOPERA = ua.indexOf('Opera') != -1;
  88. agl.ISCHROME = ua.indexOf('Chrome') != -1;
  89. agl.ISSAFARI = ua.indexOf('Safari') != -1 && !agl.ISCHROME;
  90. agl.ISWEBKIT = ua.indexOf('WebKit') != -1;
  91.  
  92. agl.ISIE = ua.indexOf('Trident') > 0 || navigator.userAgent.indexOf('MSIE') > 0;
  93. agl.ISIE6 = ua.indexOf('MSIE 6') > 0;
  94. agl.ISIE7 = ua.indexOf('MSIE 7') > 0;
  95. agl.ISIE8 = ua.indexOf('MSIE 8') > 0;
  96. agl.ISIE9 = ua.indexOf('MSIE 9') > 0;
  97. agl.ISIE10 = ua.indexOf('MSIE 10') > 0;
  98. agl.ISOLD = agl.ISIE6 || agl.ISIE7 || agl.ISIE8; // MUST be here
  99.  
  100. agl.ISIE11UP = ua.indexOf('MSIE') == -1 && ua.indexOf('Trident') > 0;
  101. agl.ISIE10UP = agl.ISIE10 || agl.ISIE11UP;
  102. agl.ISIE9UP = agl.ISIE9 || agl.ISIE10UP;
  103.  
  104. })(window, window.angular);
  105.  
  106. function SampleController($scope){
  107. $scope.click = function () {
  108. if(angular.ISCHROME) {
  109. alert("is chrome");
  110. }
  111. }
  112.  
  113. angular.module('myModule').service('browserDetectionService', function() {
  114.  
  115. return {
  116. isCompatible: function () {
  117.  
  118. var browserInfo = navigator.userAgent;
  119. var browserFlags = {};
  120.  
  121. browserFlags.ISFF = browserInfo.indexOf('Firefox') != -1;
  122. browserFlags.ISOPERA = browserInfo.indexOf('Opera') != -1;
  123. browserFlags.ISCHROME = browserInfo.indexOf('Chrome') != -1;
  124. browserFlags.ISSAFARI = browserInfo.indexOf('Safari') != -1 && !browserFlags.ISCHROME;
  125. browserFlags.ISWEBKIT = browserInfo.indexOf('WebKit') != -1;
  126.  
  127. browserFlags.ISIE = browserInfo.indexOf('Trident') > 0 || navigator.userAgent.indexOf('MSIE') > 0;
  128. browserFlags.ISIE6 = browserInfo.indexOf('MSIE 6') > 0;
  129. browserFlags.ISIE7 = browserInfo.indexOf('MSIE 7') > 0;
  130. browserFlags.ISIE8 = browserInfo.indexOf('MSIE 8') > 0;
  131. browserFlags.ISIE9 = browserInfo.indexOf('MSIE 9') > 0;
  132. browserFlags.ISIE10 = browserInfo.indexOf('MSIE 10') > 0;
  133. browserFlags.ISOLD = browserFlags.ISIE6 || browserFlags.ISIE7 || browserFlags.ISIE8 || browserFlags.ISIE9; // MUST be here
  134.  
  135. browserFlags.ISIE11UP = browserInfo.indexOf('MSIE') == -1 && browserInfo.indexOf('Trident') > 0;
  136. browserFlags.ISIE10UP = browserFlags.ISIE10 || browserFlags.ISIE11UP;
  137. browserFlags.ISIE9UP = browserFlags.ISIE9 || browserFlags.ISIE10UP;
  138.  
  139. return !browserFlags.ISOLD;
  140. }
  141. };
  142.  
  143. });
  144.  
  145. var doc = $window.document;
  146. if (!!doc.documentMode)
  147. {
  148. if (doc.documentMode === 10)
  149. {
  150. doc.documentElement.className += ' isIE isIE10';
  151. }
  152. else if (doc.documentMode === 11)
  153. {
  154. doc.documentElement.className += ' isIE isIE11';
  155. }
  156. // etc.
  157. }
  158.  
  159. var userAgent, ieReg, ie;
  160. userAgent = $window.navigator.userAgent;
  161. ieReg = /msie|Trident.*rv[ :]*11./gi;
  162. ie = ieReg.test(userAgent);
  163.  
  164. if (ie) {
  165. // js for ie9,10 and 11
  166. }
Add Comment
Please, Sign In to add comment