Detect all Firefox versions in JS Detect all Firefox versions in JS javascript javascript

Detect all Firefox versions in JS


This will detect any version of Firefox:

var isFirefox = navigator.userAgent.toLowerCase().indexOf('firefox') > -1;

more specifically:

if(navigator.userAgent.toLowerCase().indexOf('firefox') > -1){     // Do Firefox-related activities}

You may want to consider using feature-detection ala Modernizr, or a related tool, to accomplish what you need.


If you'd like to know what is the numeric version of FireFox you can use the following snippet:

var match = window.navigator.userAgent.match(/Firefox\/([0-9]+)\./);var ver = match ? parseInt(match[1]) : 0;


For a long time I have used the alternative:

('netscape' in window) && / rv:/.test(navigator.userAgent)

because I don't trust user agent strings. Some bugs are not detectable using feature detection, so detecting the browser is required for some workarounds.

Also if you are working around a bug in Gecko, then the bug is probably also in derivatives of Firefox, and this code should work with derivatives too (Do Waterfox and Pale Moon have 'Firefox' in the user agent string?).