I am going to explain you example of get browser name in angular. let’s discuss about get browser version angular. if you have question about check browser version angular then i will give simple example with solution. This article goes in detailed on get browser name and version in angular. You just need to some step to done angular get browser name and version.
I will give you very simple example of getting browser name and version in angular. you can easily use this example in angular 6, angular 7, angular 8 and angular 9 version for detect browser name and version.
in this example i created two functions one is myBrowser() for check browser name and another is getBrowserVersion() for check browser version.
Let's see simple example and use in your app
Example:
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'my-app',
templateUrl: './app.component.html',
styleUrls: [ './app.component.css' ]
})
export class AppComponent implements OnInit {
name = 'Angular';
ngOnInit() {
console.log(this.myBrowser());
console.log(this.getBrowserVersion());
}
myBrowser() {
if((navigator.userAgent.indexOf("Opera") || navigator.userAgent.indexOf('OPR')) != -1 ) {
return 'Opera';
}else if(navigator.userAgent.indexOf("Chrome") != -1 ){
return 'Chrome';
}else if(navigator.userAgent.indexOf("Safari") != -1){
return 'Safari';
}else if(navigator.userAgent.indexOf("Firefox") != -1 ) {
return 'Firefox';
}else if((navigator.userAgent.indexOf("MSIE") != -1 ) || (!!document.documentMode == true )){
return 'IE';
} else {
return 'unknown';
}
}
getBrowserVersion(){
var userAgent= navigator.userAgent, tem,
matchTest= userAgent.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*(\d+)/i) || [];
if(/trident/i.test(matchTest[1])){
tem= /\brv[ :]+(\d+)/g.exec(userAgent) || [];
return 'IE '+(tem[1] || '');
}
if(matchTest[1]=== 'Chrome'){
tem= userAgent.match(/\b(OPR|Edge)\/(\d+)/);
if(tem!= null) return tem.slice(1).join(' ').replace('OPR', 'Opera');
}
matchTest= matchTest[2]? [matchTest[1], matchTest[2]]: [navigator.appName, navigator.appVersion, '-?'];
if((tem= userAgent.match(/version\/(\d+)/i))!= null) matchTest.splice(1, 1, tem[1]);
return matchTest.join(' ');
}
}
Output:
Chrome
Chrome 81
I hope it can help you...
Do you like below Tutorials ?
- PHP Laravel 5.5 - import export data into excel and csv using maatwebsite
- Laravel 7.x and 6.x create custom facade example from scratch
- Node JS - Get Real time online users counter using socket io example
- PHP Laravel 7.x and 6.x - Bootstrap Admin Theme Integration example from scratch
- MySQL Query - How to select records of today to next Sunday ?
- Laravel 7.x and 6.x - username custom validation example
- Laravel 5.5 - Import Extract zip file using chumper/zipper package
- PHP Laravel Set Custom Validation Error Messages Example