Try OpenEdge Now
skip to main content
Developing WebSpeed Applications
Using JavaScript with WebSpeed : Some JavaScript examples : Browser detection

Browser detection

The following JavaScript code snippet contains a simple method for determining whether a browser is Internet Explorer or Netscape Navigator. It tests for the existence of the document.all object, which is only available on Internet Explorer. Then it tests for the existence of the document.layers object, which is only available on Netscape Navigator, as shown:
var isIE = false;
var isNav = false;
if (document.all)
  isIE = TRUE;
else if (document.layers)
  isNav = TRUE;
An alternative method for browser detection is to use SpeedScript to create a test in your WebSpeed web object which, of course, runs on the server side. The following test, written in SpeedScript, checks for the value of the CGI environment variable, HTTP_USER_AGENT:
CGI environment variables are set automatically when web requests are received by a WebSpeed agent. In this case, if the value of HTTP_USER_AGENT is MSIE, then the client request came from an Internet Explorer Web browser.