0

I'm working on a snippet for check if the browser is Firefox/Firefox OS/Firefox for Android. The method for check is the user agent with a little feature detection.

I haven't found a better way with a complete feature detection that cover all the cases.

The gist it's here: https://gist.github.com/Mte90/11087393

Any solution more professional?

Sam Hanley
  • 4,707
  • 7
  • 35
  • 63
Mte90
  • 115
  • 3
  • 13
  • What is the underlying need that drives you to want to do browser detection in the first place? – Pointy Apr 19 '14 at 15:23
  • do not understand, what do you mean by "professional"? – Protomen Apr 19 '14 at 15:24
  • I need the detection for load different code. For professional i refer to a better solution that don't use the user agent string. – Mte90 Apr 19 '14 at 15:48
  • would have been better to say you need a more "secure solution" (because UserAgentString can be manipulated). I have the simulator Firefox, but was unable to see different functions of the desktop. – Protomen Apr 19 '14 at 16:10

1 Answers1

0

As far as I know, there is no other way to do this, but I would suggest you do features detection when you need to use something specific, instead of using user-agent. As an example, you can use

if (navigator.connection) //Network Information API
if (navigator.battery) // Battery Status API

Or use a library like Modernizr.

fharper
  • 559
  • 2
  • 13
  • connection and battery exist in all the Firefox/Firefox OS/Firefox for Android :-/ – Mte90 Apr 22 '14 at 14:19
  • Yes, it's why feature detection is working. Maybe I do not understand what you want to achieve... – fharper Apr 22 '14 at 18:19
  • A feature that have only Firefox for Android for example? Only Firefox? Firefox OS is simple (web activity). – Mte90 Apr 22 '14 at 20:09
  • The code will only enter the if if the feature is available on the platform. What do you want to do different on those platforms if it's not related to using specific APIs? – fharper Apr 24 '14 at 20:18
  • Ok, for remove the user agent i need to check for a specific api of Firefox OS, one of Firefox for android and one of Firefox. So with this i con use the feature detection. I have not found a specific api of these ambient for not use the user agent. You can help me? – Mte90 Apr 26 '14 at 19:57