In this article, we are going to find browser version and name in Angular 11. In this article, we will detect browser and version, then we’ll check whether it complies with the minimum accepted version we have set.
Prerequisites!
- Should have a working Angular project. (Create Angular Project)
Table of Content
- Why detect browser and version?
- Create a basic HTML layout in Angular
- Detect Browser and Version in Angular
Why detect browser and version?
There are times when our Angular application does not support certain browsers or certain versions of those browsers. A common example would be Internet Explorer. So, to tackle this problem, we need to find browser version and browser name. This way you can either make an alert notification or redirect to another page to restrict the user.
Create a basic HTML layout in Angular
We are going to show the results to find browser version and browser name in Angular. For that, we will write a basic HTML layout to see the output.
First thing first, create a fresh new Angular Project named “detectBrowser”. Once it’s created, copy the below code in the “app.component.html”.
Detect Browser Name and Its Version
The above code is a very minimalistic HTML layout with only 2 fields where the browser name and version would be shown. Now that our HTML layout is made, we will write JavaScript detect browser. Now copy the below code in “app.component.ts”. Here I have only initialized 2 variables for now.
export class AppComponent {
browserName = 'Browser Name';
browserVersion = 'Browser Version';
}
Next, start the project with this command:
ng serve
The image below shows how the project would look once you run it.
Detect Browser and Version in Angular
Now that we are done with setting up a basic layout, let’s move on to the good stuff! Go to the “app.component.ts” file again. The below code is of JavaScript detect browser version and name. Copy and overwrite the whole of the “AppComponent” function list so:
export class AppComponent {
browserName = 'Browser Name';
browserVersion = 'Browser Version';
ngOnInit() {
this.browserName = this.detectBrowserName();
this.browserVersion = this.detectBrowserVersion();
}
detectBrowserName() {
const agent = window.navigator.userAgent.toLowerCase()
switch (true) {
case agent.indexOf('edge') > -1:
return 'edge';
case agent.indexOf('opr') > -1 && !!(window).opr:
return 'opera';
case agent.indexOf('chrome') > -1 && !!(window).chrome:
return 'chrome';
case agent.indexOf('trident') > -1:
return 'ie';
case agent.indexOf('firefox') > -1:
return 'firefox';
case agent.indexOf('safari') > -1:
return 'safari';
default:
return 'other';
}
}
detectBrowserVersion() {
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(' ');
}
}
Here we have added 2 functions to detect browser and version accordingly. It will detect both and then set the values to the variables browserName and browserVersion. And since these variables are already binded in the HTML layout, you could already see the output now. You can check it against a couple of browsers and see that it works perfectly. After running the project on Chrome, you will see the following output.
So that’s a wrap!
We hope this tutorial helped you learn how to Find Browser Version and Name in Angular 11. You may also want to learn how to add SweetAlerts in Angular project or how to detect internet connection status in Angular 13.
Have a great one!
Recent Posts
- Zonder Cruks Online Casino Veiligheid en beveiliging van spelers.1175
- Fortune Favors the Bold – Can You Lead Your Clucky Companion Down the Chicken Road & Cash Out Before
- Verfrissend Gokken met nieuwe online casino zonder cruks – Een Nieuwe Ervaring
- Elevate Your Play Find the best australian online casino Experiences with Lucrative Bonuses & Secure
- Lopebet’s Multi-Bet Options: How and When to Use Them
Recent Comments
Archives
- May 2026
- October 2025
- August 2025
- June 2025
- October 2024
- September 2024
- August 2024
- June 2023
- May 2023
- March 2023
- December 2022
- November 2022
- October 2022
- September 2022
- August 2022
- July 2022
- June 2022
- May 2022
- April 2022
- February 2022
- January 2022
- December 2021
- November 2021
- October 2021
- September 2021
- August 2021
- July 2021
Categories
- Angular
- AWS
- Backend Development
- Big Data
- Casino
- Cloud
- Database
- Deployment
- DevOps
- Docker
- Frontend Development
- GitHub
- Google Cloud Platform
- Installations
- Java
- JavaScript
- Linux
- MySQL
- Networking
- News
- NodeJS
- Online casino
- Operating System
- Post
- Python
- Python Flask
- Report
- Security
- Server
- SpringBoot
- Subdomain
- TypeScript
- Uncategorized
- VSCode
- Webhosting
- WordPress
Search
Recent Post
Zonder Cruks Online Casino Veiligheid en beveiliging
- 18 May, 2026
- 5 min read
Fortune Favors the Bold – Can You
- 15 May, 2026
- 6 min read
Verfrissend Gokken met nieuwe online casino zonder
- 14 May, 2026
- 6 min read