etecting user browser sometimes very useful if we want to write our logic based on the browser. Sometimes we
need to do some specific things
based on the browser or sometimes some functionality may not support in different browser so we need to
detect the user browser and write our logic.
To get the user browser, we have navigator object which contains the userAgent. And in this navigator.userAgent it contains the browser specific information.
So, let's see how we can detect the browser using navigator.userAgent.
Let's create a file with name detect-browser.html and write the below codes:
In the above code we have a button Detect browser and after clicking on this button, it'll call a function checkBrowser() And in this function we wrote the logic to detect the browser.
Test on Chrome:
Open the above file in the chrome browser and see the output as:
Now click on the Detect browser button and see the result. After clicking the button Detect browser you can see a popup with the browser name as:
Test on Firefox:
Now, open this html file into firefox browser and click on the button Detect browser and see the result as:
Test on Safari:
Now, open this html file into safari browser and click on the button Detect browser and see the result as:
Strongly Recommended Books For You:
For Other Countries (United States, United Kingdom, Spain, Italy, Germany, France, Canada, etc)
If you found this article is helpful, then please share this article's link to your friends to whom this is required, you can share this to your technical social media groups also. You can follow us on our social media page for more updates and latest article updates.
To read more about the technologies, Please subscribe us, You'll get the monthly newsletter having all the published article of the last month.