Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var browserVersion = int((/msie (d+)/.exec(lowercase(navigator.userAgent)) || [])[1]);
- app.service('browser', ['$window', function($window) {
- return function() {
- var userAgent = $window.navigator.userAgent;
- var browsers = {chrome: /chrome/i, safari: /safari/i, firefox: /firefox/i, ie: /internet explorer/i};
- for(var key in browsers) {
- if (browsers[key].test(userAgent)) {
- return key;
- }
- };
- return 'unknown';
- }
- }]);
- angular.module('yourModule').value('bowser', bowser);
- detectFactory.$inject = ['$window'];
- function detectFactory($window) {
- return detect.parse($window.navigator.userAgent);
- }
- angular.module('yourModule').factory('detect', detectFactory);
- function someLibFactory() {
- return new SomeLib();
- }
- angular.module('yourModule').factory('someLib', someLibFactory);
- BrowserAdapter.$inject = ['bowser']; // bring in lib
- function BrowserAdapter(bowser) {
- this.bowser = bowser;
- }
- BrowserAdapter.prototype.isIe9 = function() {
- return this.bowser.msie && this.browser.version == 9;
- }
- angular.module('yourModule').service('browserAdapter', BrowserAdapter);
- angular.module('app').value('isIe9', broswerAdapter.isIe9);
- /**
- * documentMode is an IE-only property
- * http://msdn.microsoft.com/en-us/library/ie/cc196988(v=vs.85).aspx
- */
- var msie = document.documentMode;
- // var msie = document.documentMode;
- var msie = $document[0].documentMode;
- // if is IE (documentMode contains IE version)
- if (msie) {
- // IE logic here
- if (msie === 9) {
- // IE 9 logic here
- }
- }
- <!--[if IE 9]>
- <script type="text/javascript">
- window.isIE9 = true;
- </script>
- <![endif]-->
- //Detect if IE 9
- if(navigator.appVersion.indexOf("MSIE 9.")!=-1)
- var app = angular.module('myapp', ["ng.deviceDetector"]);
- app.controller('DeviceCtrl', ["$scope","deviceDetector",function($scope,deviceDetector) {
- console.log("browser: ", deviceDetector.browser);
- console.log("browser version: ", deviceDetector.browser_version);
- console.log("device: ", deviceDetector.device);
- }]);
- (function(window, angular, undefined) {'use strict';
- var agl = angular || {};
- var ua = navigator.userAgent;
- agl.ISFF = ua.indexOf('Firefox') != -1;
- agl.ISOPERA = ua.indexOf('Opera') != -1;
- agl.ISCHROME = ua.indexOf('Chrome') != -1;
- agl.ISSAFARI = ua.indexOf('Safari') != -1 && !agl.ISCHROME;
- agl.ISWEBKIT = ua.indexOf('WebKit') != -1;
- agl.ISIE = ua.indexOf('Trident') > 0 || navigator.userAgent.indexOf('MSIE') > 0;
- agl.ISIE6 = ua.indexOf('MSIE 6') > 0;
- agl.ISIE7 = ua.indexOf('MSIE 7') > 0;
- agl.ISIE8 = ua.indexOf('MSIE 8') > 0;
- agl.ISIE9 = ua.indexOf('MSIE 9') > 0;
- agl.ISIE10 = ua.indexOf('MSIE 10') > 0;
- agl.ISOLD = agl.ISIE6 || agl.ISIE7 || agl.ISIE8; // MUST be here
- agl.ISIE11UP = ua.indexOf('MSIE') == -1 && ua.indexOf('Trident') > 0;
- agl.ISIE10UP = agl.ISIE10 || agl.ISIE11UP;
- agl.ISIE9UP = agl.ISIE9 || agl.ISIE10UP;
- })(window, window.angular);
- function SampleController($scope){
- $scope.click = function () {
- if(angular.ISCHROME) {
- alert("is chrome");
- }
- }
- angular.module('myModule').service('browserDetectionService', function() {
- return {
- isCompatible: function () {
- var browserInfo = navigator.userAgent;
- var browserFlags = {};
- browserFlags.ISFF = browserInfo.indexOf('Firefox') != -1;
- browserFlags.ISOPERA = browserInfo.indexOf('Opera') != -1;
- browserFlags.ISCHROME = browserInfo.indexOf('Chrome') != -1;
- browserFlags.ISSAFARI = browserInfo.indexOf('Safari') != -1 && !browserFlags.ISCHROME;
- browserFlags.ISWEBKIT = browserInfo.indexOf('WebKit') != -1;
- browserFlags.ISIE = browserInfo.indexOf('Trident') > 0 || navigator.userAgent.indexOf('MSIE') > 0;
- browserFlags.ISIE6 = browserInfo.indexOf('MSIE 6') > 0;
- browserFlags.ISIE7 = browserInfo.indexOf('MSIE 7') > 0;
- browserFlags.ISIE8 = browserInfo.indexOf('MSIE 8') > 0;
- browserFlags.ISIE9 = browserInfo.indexOf('MSIE 9') > 0;
- browserFlags.ISIE10 = browserInfo.indexOf('MSIE 10') > 0;
- browserFlags.ISOLD = browserFlags.ISIE6 || browserFlags.ISIE7 || browserFlags.ISIE8 || browserFlags.ISIE9; // MUST be here
- browserFlags.ISIE11UP = browserInfo.indexOf('MSIE') == -1 && browserInfo.indexOf('Trident') > 0;
- browserFlags.ISIE10UP = browserFlags.ISIE10 || browserFlags.ISIE11UP;
- browserFlags.ISIE9UP = browserFlags.ISIE9 || browserFlags.ISIE10UP;
- return !browserFlags.ISOLD;
- }
- };
- });
- var doc = $window.document;
- if (!!doc.documentMode)
- {
- if (doc.documentMode === 10)
- {
- doc.documentElement.className += ' isIE isIE10';
- }
- else if (doc.documentMode === 11)
- {
- doc.documentElement.className += ' isIE isIE11';
- }
- // etc.
- }
- var userAgent, ieReg, ie;
- userAgent = $window.navigator.userAgent;
- ieReg = /msie|Trident.*rv[ :]*11./gi;
- ie = ieReg.test(userAgent);
- if (ie) {
- // js for ie9,10 and 11
- }
Add Comment
Please, Sign In to add comment