Skip to content

Browser Detection

Mobile Testing & Debugging Environments
Building Custom Controls


There are lots of browsers available, and it is impossible to support them all. The Web Framework supports the most common browsers (Safari, Firefox, Chrome, and Internet Explorer). It doesn’t stop the user from using different browsers except for Internet Explorer 7 and older. The reason for not limiting this is that many browsers share their engines and follow standards, so theoretically, the framework should run on all modern browsers. The reason for blocking Internet Explorer 7 and older is that these lack features that the framework needs to run, and Internet Explorer is the browser where older versions are more common.

Within the framework, our controls usually try to detect the available APIs rather than detecting the browser. If the right function/class/object is available, it will use it; otherwise, it will fall back on alternative methods or give an error.

User Agent

To be able to detect the browser, the browser provides a user agent string. This string identifies the browser and its version. It is sent to the server with each request.

Example User Agent Strings

  • Internet Explorer 9: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)
  • Google Chrome 27: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.110 Safari/537.36
  • Mozilla Firefox 21: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:21.0) Gecko/20100101 Firefox/21.0
  • Safari for Windows 5: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/534.57.2 (KHTML, like Gecko) Version/5.1.7 Safari/534.57.2

The table above shows some examples of these browser strings. Note that there are differences in the format of the strings. For historic reasons, most browsers start their user agent string with Mozilla.

Get ServerVariable of ghoWebServiceDispatcher "HTTP_USER_AGENT" to sUserAgent

To get the user agent string in DataFlex, we use the ServerVariable method that is available on cWebService objects and cWebBusinessProcess objects (legacy ASP). Within the framework, we use the ghoWebServiceDispatcher handler that should always point to a web service object. This information is always available when handling a request, so it can be used in almost any framework event.

Show Warning

To warn users if they are not using one of our recommended browsers every time the application is opened, we implement the following in the OnLoad of the oWebApp object.

Object oWebApp is a cWebApp
    Procedure OnLoad
        String sUserAgent
        Forward Send OnLoad
        Get ServerVariable of ghoWebServiceDispatcher "HTTP_USER_AGENT" to sUserAgent
        If ((Pos("MSIE ", sUserAgent) = 0) and (Pos("Firefox", sUserAgent) = 0)) Begin
            Send UserError "It is recommended to use Internet Explorer or Firefox" "Browser check"
        End
    End_Procedure

The example above shows how to give a warning if the browser cannot be identified as being Firefox or Internet Explorer.

Block Access

Blocking access can be done in different ways. One method is to hide the menu bars using pbRender and ensure that the view/login screen doesn’t pop up (alter phoDefaultView and phoLoginDialog from the OnLoad of oWebApp). Another way is to create a special HTML landing page showing the message that the browser is not allowed. The OnLoad event could then redirect to that page using the NavigateToPage method.

Object oWebApp is a cWebApp
    Procedure OnLoad
        String sUserAgent
        Forward Send OnLoad
        Get ServerVariable of ghoWebServiceDispatcher "HTTP_USER_AGENT" to sUserAgent
        If ((Pos("MSIE ", sUserAgent) = 0) and (Pos("Firefox", sUserAgent) = 0)) Begin
            // Navigate to warning page
            Send NavigateToPage "BrowserNotAllowed.html" btCurrentWindow
        End
    End_Procedure

The example above shows how to forward to a separate HTML page when the browser is not accepted.


Previous Topic: Mobile Testing & Debugging Environments
Next Topic: Building Custom Controls

See Also