0

I need to know if the browser running my page is Firefox. I came across the code below:

 var isGecko = (navigator.product == 'Gecko');

but this is true for Firefox and Safari.

Aurelius
  • 10,121
  • 3
  • 44
  • 68
Steve
  • 3,624
  • 8
  • 44
  • 91
  • 3
    Don't. Use feature detection instead. – SLaks Jul 17 '13 at 15:55
  • This looks like it was already answered: http://stackoverflow.com/questions/2400935/browser-detection-in-javascript – turnt Jul 17 '13 at 15:56
  • 1
    SLaks, in a perfect world, I'll use nothing but feature detection. As long as things like Flash, webcam access, and other random things have weird behaviors between browsers in must-be-perfect environments...I'm going to keep regretfully browser-sniffing. – Katana314 Jul 17 '13 at 15:57

1 Answers1

3

Only Firefox has the string "Firefox" in the user agent, so it is as easy as

var isFirefox = (navigator.userAgent.indexOf('Firefox') !== -1);

Edit: yes, Mozilla discourages it

Brian
  • 6,010
  • 3
  • 20
  • 38