The navigator.userAgent property in JavaScript represents the user agent string of the current browser. It is a read-only property that returns a string value representing the user agent string.
Here is an example of how to use the navigator.userAgent property:
// check the user agent string of the current browser
if (navigator.userAgent.indexOf("Firefox") != -1) {
// do something specific for Firefox
}
In the above code, we are checking the value of the navigator.userAgent property and using the indexOf() method to check if it contains the string “Firefox”. If it does, we can execute some code that is specific to Firefox.
Note that the value of the navigator.userAgent property may vary depending on the browser being used and its version. For example, it may return “Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:80.0) Gecko/20100101 Firefox/80.0” for Firefox 80 on Windows 10, “Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.102 Safari/537.36” for Chrome 85 on Windows 10, or “Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.1.2 Safari/605.1.15” for Safari 13.1 on Mac OS X 10.15.6.
Leave a Reply