JavaScript – Get Firefox Browser Version

This post shows you how to get the version of Firefox browser using JavaScript.

To do this, we simply look at User-Agent data (navigator.userAgent) to determine whether the visitors are using Firefox browser and then extract Firefox version from it.

 

Here is the code:

firefox-browser.js
function getFirefoxVersion() {
    var version = null;

    var userAgent = navigator.userAgent.toLowerCase();
    if (userAgent.indexOf('firefox') !== -1) {
        var matches = userAgent.match(/firefox\/([0-9]+\.*[0-9]*)/);
        if (matches) {
            version = matches[1];
        }
    }

    return version;
}

 

Use the function:

// Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:60.0) Gecko/20100101 Firefox/60.0
var firefoxVersion = getFirefoxVersion();
console.log(firefoxVersion);

Output:

60.0

Leave a Reply

avatar