Client Side Overrides
When used with the Enterprise version of the data set, the API can augment static data about devices with dynamic information determined by interrogating the device using javascript to determine additional information. Examples include:
- The User-Agent of an iPhone does not provide sufficient information to determine the model of iPhone. This is a deliberate choice Apple have made. However javascript running in an iPhone browser can be used to determine the screen size and therefore the numeric model version.
- The device may be used in Landscape or Portrait orientation which is not a static feature of the device.
Feature detection when enabled enhances properties in the 51Degrees dictionary to provider additional details. Once enabled properties such as HardwareModel or Orientation will become more accurate or populated.
Important: Before invoking the FODPO() javascript object on the client side, a check must be carried out on the server for the presence of values in JavascriptHardwareProfile as shown in the snippet below:
public class MyServlet extends BaseServlet { /** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods. * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest ( HttpServletRequest request , HttpServletResponse response ) throws ServletException , IOException { response . setContentType ( "text/html;charset=UTF-8" ); try ( PrintWriter out = response . getWriter ()) { /* TODO output your page here. You may use following sample code. */ out . println ( "<!DOCTYPE html>" ); out . println ( "<html>" ); out . println ( "<head>" ); if ( super . getProvider ( request ). match ( request ). getValues ( "JavascriptHardwareProfile" ) != null ) { //This is an iPhone so, deploy javasript for FODPO(); out . println ( "<script src=\"51D/core.js\" > </script>" ); out . println ( "<script>" + "new FODPO();" + "</script>" ); } else { //Include alternative javascript if required. } out . println ( "<title>Servlet MyServlet</title>" ); out . println ( "</head>" ); out . println ( "<body>" ); out . println ( "<h1>Servlet MyServlet at " + request . getContextPath () + "</h1>" ); out . println ( "<HR>" ); out . println ( "<p> Data set name: " + super . getProvider ( request ). dataSet . getName ()+ "</p>" ); out . println ( "</body>" ); out . println ( "</html>" ); } }
The above snippet represents the class called MyServlet that implements a Java servlet. The class extends the BaseServlet from the package fiftyone.mobile.detection.webapp.BaseServlet. The bit that performs the check starts right after the out.println("<head>"); line. If JavascriptHardwareProfile is not null then the FODPO(); script will be added to the page.