asp.net.ph

Skip Navigation Links

userAgent Property

Language References


Retrieves a string equivalent to the HTTP user-agent request header.

Syntax


HTML N/A
Script [ sUserAgent = ] navigator.userAgent

Possible Values


sUserAgent String specifying a valid HTTP user agent.

The property is read-only with a browser-specific default value.

Example

The following script detects the current user's browser and displays its appName and userAgent attributes in an alert box.

<script language="JavaScript">
<!--
function getBrowser ( ) {
   var browser = navigator.appName;
   browser += "\n" + navigator.userAgent;
   alert ( browser );
}
//-->
</script>

 Show me 

This attribute can be used to determine the user's operating system, for example, if using a Windows NT operating system was a requirement for the script. A variable "isNT" checks to see if the string "NT" is found in the string returned by userAgent; if not, the variable is set to -1. Other scripts can then refer to the variable as needed.

<script language="JavaScript">
var isNT = navigator.userAgent.indexOf ( "NT" );
if ( isNT > 1 )
  ... code for WinNT
else
  ... code for others
</script>
Applies To

navigator


See Also

appCodeName, appMinorVersion, appName, appVersion



>

© 2025 Reynald Nuñez and asp.net.ph. All rights reserved.

If you have any question, comment or suggestion
about this site, please send us a note