Retrieving Browser Information from Cookies

As discussed previously, the Browser Capabilities component can now retrieve client browser capability information from a cookie accompanying the HTTP request sent by the client. Although you can compile this cookie and send it from the client with the HTTP request any way you like, the most seamless and automatic way is by the use of behaviors.

Here's how it works. First we need to create the cookie. You can accomplish this with something resembling the following code snippet:

function window.onload ( )
{
  // Note the bdyCCaps is the value for the ID parameter of the BODY tag.
  // The clientCaps behaviour is provided with IE5.
  bdyCCaps.style.behavior = "url(#default#clientCaps)";

  // Determine width and height and add it to the cookie string.
  strCookieString   =  "width= " + bdyCCaps.width;
  strCookieString  +=  "&height= " + bdyCCaps.height;

  // Determine the color depth for the client machine and 
  // add it to the cookie string.
  strCookieString  +=  "&colorDepth= " + bdyCCaps.colorDepth;

  // Determine whether the client has cookies enabled and 
  // add it to the cookie string.
  strCookieString  +=  "&cookies= " + bdyCCaps.cookieEnabled;

  // Add the cookie string to the Browser Cap cookie to be sent
  // to the server.
  document.cookie = "BrowsCap= " + strCookieString;
}

For more information on the use of behaviors and their importance, see the Microsoft web site. For now, you only need to know that the following properties are available in the clientCaps behavior ...

Get ASP in a Nutshell, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.