Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect browser with Angular?

I need to detect if browser is IE or Edge with Angular (TypeScript). Is it possible? If so, how?

like image 527
Liutas Avatar asked Jan 10 '18 08:01

Liutas


People also ask

Does angular work on all browsers?

Angular offers a cross browser compatibility for web apps, with the recent versions of Angular supporting all the latest versions of browsers like Firefox, Chrome, Safari, and many more. Web applications developed in Angular sometimes may also include animations.


2 Answers

I have used this before and it worked well.

const isIEOrEdge = /msie\s|trident\/|edge\//i.test(window.navigator.userAgent) 
like image 154
argoo Avatar answered Sep 25 '22 06:09

argoo


Please use the following code:

// Opera 8.0+      var isOpera = (!!window.opr && !!opr.addons) || !!window.opera || navigator.userAgent.indexOf(' OPR/') >= 0;        // Firefox 1.0+      var isFirefox = typeof InstallTrigger !== 'undefined';        // Safari 3.0+ "[object HTMLElementConstructor]"       var isSafari = /constructor/i.test(window.HTMLElement) || (function (p) { return p.toString() === "[object SafariRemoteNotification]"; })(!window['safari'] || safari.pushNotification);        // Internet Explorer 6-11      var isIE = /*@cc_on!@*/false || !!document.documentMode;        // Edge 20+      var isEdge = !isIE && !!window.StyleMedia;        // Chrome 1+      //var isChrome = !!window.chrome && !!window.chrome.webstore;      // If isChrome is undefined, then use:      var isChrome = !!window.chrome && (!!window.chrome.webstore || !!window.chrome.runtime);      // Blink engine detection      var isBlink = (isChrome || isOpera) && !!window.CSS;        var output = 'Detecting browsers by ducktyping:<hr>';      output += 'isFirefox: ' + isFirefox + '<br>';      output += 'isChrome: ' + isChrome + '<br>';      output += 'isSafari: ' + isSafari + '<br>';      output += 'isOpera: ' + isOpera + '<br>';      output += 'isIE: ' + isIE + '<br>';      output += 'isEdge: ' + isEdge + '<br>';      output += 'isBlink: ' + isBlink + '<br>';      document.body.innerHTML = output;
like image 22
I. Ahmed Avatar answered Sep 26 '22 06:09

I. Ahmed