Browser Detection in JavaScript
Determining the exact browser and version using JavaScript can be useful for a variety of purposes, such as providing customized experiences based on a user's browser capabilities. Here's how it can be achieved:
The navigator.saysWho() function is a JavaScript solution that provides a cross-browser method to detect and identify the exact browser and its version. It examines the userAgent string in the navigator object, which contains information about the browser being used.
The function begins by matching common browser signatures and versions against the userAgent string using regular expressions. If the match corresponds to a known browser, the function returns a string indicating the browser name and version.
For example, if the userAgent string contains "Chrome" and a version number, the function will return "Chrome" followed by the version number. Similarly, if "MSIE" or "trident" is detected, the function will return "IE" followed by the version number.
The navigator.saysWho() function is also able to detect less common browsers, such as Opera and Edge Chromium, by matching their respective signatures and version numbers.
To use the function, simply call navigator.saysWho() to retrieve the browser name and version as a string.
console.log(navigator.saysWho()); // outputs: "Chrome 89"
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3