Language References
Retrieves a string equivalent to the HTTP user-agent request header.
HTML |
N/A |
Script |
[ sUserAgent = ] navigator.userAgent |
sUserAgent |
String specifying a valid HTTP user agent. |
The property is read-only with a browser-specific default value.
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>
navigator