• About Us
  • Blog
  • Basket
  • Account
  • Sign In


Java Script

51Degrees code and data integrate well with both server side and client side frameworks and libraries. You can use server side device detection to augment your JavaScript with 51Degrees properties.

This feature will be useful for Web sites and projects that primarily use JavaScript to generate pages and fetch content on client devices. More often than not you will still need to know if the requesting device is mobile (or not) and if it supports features such as HTML canvas. This can be achieved by maintaining a set of regular expressions that will run first to determine if the device is mobile and would only then allow the main JavaScript logic to fetch content. This approach is far from ideal:  it can be inaccurate and only provides a fraction of the information that is available in the 51Degrees data files.

By using server side device detection you can obtain a fuller list of properties that are of interest to you and include them in your JavaScript page or application. This approach speeds up the loading time on your client devices, provides considerably more data for mobile devices and removes the overhead of manually maintaining a set of regular expressions for device detection.

Using Detection Results in Java Script

An optional include script can be added to the web page to provide information to client side javascript concerning the device enabling decisions to be taken in javascript. The javascript returned will create an object called FODF (51Degrees Features) which can be used to request properties. For example: the following JavaScript would return the IsMobile value:

if (FODF.IsMobile) {
  // Do something for mobiles only.

The value returned will be of a type associated with the property. See the Property Dictionary for details of property types.

Adding to a Web Page

The necessary javascript includes need to be added into the page. The following needs to be added to the HTML page header before accessing the FODF variable:

<script src="/51Degrees.features.js" type="text/javascript"></script>