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. Reason for not limiting this is because a lot of 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 because these lack features that the framework need 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 API’s rather than detecting the browser. If the right function / class / object is available it will use it, else it will fall back on alternative methods or give an error.
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.
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.
So let’s say we want 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.
Blocking access can be done in different ways. One could be to hide the menu bars using pbRender and make sure that the view / login screen doesn’t popup (alter phoDefaultView and phoLoginDialog from the OnLoad of oWebApp). Another way could be 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