How to detect the version of a browser ?
In some cases, it becomes very important to know the client’s web browser for delivering some content or information appropriately. Basically, it allows you to know the client web browser version and name and here we need to write different functions for different browsers for the purpose of detection.
Browser Detection: Mainly there are two objects that are used for browser detection which is as follows:
The purpose of the first object is to determine the web browser whereas the purpose of the second one is to determine the version of the web browser.
For Example, if the browser is Mozilla Firefox, navigator.appName returns the string “Mozilla Firefox”. If it is Edge, navigator.appName returns the string “Microsoft Edge”. Using both objects, we can create an alert box to display what web browser the client is using and this navigator object contain all the information about web browser version, name, and more.
- Below Output represents the output of browser detection for “Chrome”
Name of Browser = Chrome Full version = 86.0.4240.183 Major version = 86 navigator.appName = Netscape navigator.userAgent = Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.183 Safari/537.36
- Below Output represents the output of browser detection for “Mozilla Firefox”
Name of Browser = Firefox Full version = 5 Major version = 5 navigator.appName = Netscape navigator.userAgent = Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:80.0) Gecko/20100101 Firefox/80.0
Conclusion: This article starts with the theory of browser detection and later on it explains the browser detection scheme and script for detection. It is very beneficial in the current environment because all browsers support this application. So detect/find the browser and then write the corresponding code.