getUserAgent (XSPUserAgent - JavaScript)

Gets the entire User-Agent field of the HTTP header.

Defined in

XSPContext (JavaScript)

Syntax

getUserAgent() : string
Return value Description
string The entire user agent string sent by the browser.

Usage

The format and content of the string depends on the browser sending the request. Here are sample user agent strings returned by Firefox 3 and IE 6:
  • Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.1) Gecko/2008070208 Firefox/3.0.1
  • Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322)

Examples

This computed field displays the browser and version, or the complete user agent string if the browser is not identified:
var browser = context.getUserAgent().getBrowser();
if(!browser.isEmpty()) {
	return browser + " " + context.getUserAgent().getBrowserVersion();
} else {
	return context.getUserAgent().getUserAgent();
}