Detect if app is running on Firefox OS using JavaScript

While we live in an time of Responsive Web Design where a webApp is expected to adapt to any screen (and device) it is still useful to have some way of checking if you are running this or that platform in order to add platform-dependent features. In FirefoxOS’s case maybe we want to add listeners for web activities, or code meant for other web APIs. I was playing around with the idea of a page that loads a different set of UI elements on a Firefox OS phone so I could try out the (currently) unstable Building Block Drawer. PhoneGap is a widely used framework for this kind of things, but it does not support Firefox OS just yet.

Thankfully there is another framework that already does this called Enyo. I have not tried it extensively, but it looks like a pretty complete framework for building webApps. The thing is, maybe you have a project already going and you do not want to add an entire framework just for this feature like I was. Thankfully, you can add just a Javascript library from the framework to get it to work.

  1. Go to Enyo’s download page and download their Bootplate zip.
  2. Unzip and look for a build folder
  3. Copy the enyo.js library from the folder into your project and import. All done!

Now all you need to do in JavaScript is:

if(enyo.platform.firefoxOS) {
    //do FirefoxOS especific stuff

Hope it helps!


An upcoming web developer and android app-maker with an interest on using reliable tech in creative ways, open source projects and start-ups.

Tagged with: , , , ,
Posted in developer tips

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: