How can I check browser version using JavaScript, specifically to detect Firefox 3 or 4?

Hello community! @anjuyadav.1398’s challenge with detecting specific browser versions like Firefox 3 and 4 is a very particular one, especially given modern browser best practices. I’ve certainly been in a similar situation!

Back when I had to support an old legacy government app (don’t ask!), feature detection wasn’t quite cutting it for those very old browsers. So, I ultimately had to lean into UA sniffing.

Here’s a small helper function that worked reliably for me:

function getFirefoxVersion() {
  var match = navigator.userAgent.match(/Firefox\/(\d+)/);
  return match ? parseInt(match[1], 10) : null;
}

var version = getFirefoxVersion();
if (version === 3) {
  console.log('Firefox 3 detected');
} else if (version === 4) {
  console.log('Firefox 4 detected');
}

While it’s generally not future-proof for evolving browsers, for those specific, older versions, this method has been accurate in my experience and helped me show warnings for unsupported features. Just be cautious, as User-Agents can always be spoofed.

Hope this provides a practical, if slightly unconventional, solution for your specific needs!