Similar Post
How to detect if browser supports WebP format on server side PHP script?
A bad idea?
If you’re planning to server your users different pages based on their browser choices then yes, it’s a bad idea.
Keep your content same for all of your users no matter their browser choices.
If the browser doesn’t support some features then that’s a different story. But please don’t discriminate your users. There is already enough discrimination in the world already!
When it’s a good idea?
Different browsers have different standards even if they are using the same engine.
Let’s talk about a real life example. When you have an app that relies on the browser standards to render the page and to apply the style. Now, you want to create a PDF from that html rendered page and you’re using a third party library to create the PDF.
Let’s say Mozilla Firefox applies the height differently than Google Chrome and the PDF generated by both browsers are completely different. Now, if you detect the browser and apply a specific height for Mozilla Firefox, it solves the issue.
The example is simple and sometimes you have a bigger problems than that and to solve those, you might need to detect the browser and adjust your scripts.
You’re not changing the contents but changing your code in order to represent the contents consistently across the browsers.
Navigator.userAgent
The Navigator.userAgent property returns the user agent string for the browser the user is on to access your app.
We can make use of Navigator.userAgent to make a JavaScript function and detect the browser.
Take a look at more info on Navigator.userAgent
browsers chrome cross-browser detection examples firefox functions User Agent