request.agent

NES2+Syntax

request.agent

Description

The agent property of the request object contains the user agent string of the requesting application. The following is an example of a user agent string for Navigator 4.5 on Windows 98.

Mozilla/4.5 [en] (Win98; U)

You can use several methods of the String object in conjunction with this property to determine the type and version of the browser requesting the page.

Example

Listing 8.104 examines the requesting browser's agent string and redirects Internet Explorer browsers to an alternative page.

Listing 8.104 Accessing the agent Property of the request Object
 <SERVER> // Check to see if the browser is Internet Explorer if(request.agent.indexOf('MSIE') != -1){ redirect(addClient("/iepages/index.html")); ...

Get Pure JavaScript 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.