Monday, December 17, 2007

How to detect which browser has been used by the visitor

How to detect which browser has been used by the visitor

S T E P - 1

- First, we can use HTTP_USER_AGENT Variable to get the information of the browser at client's side:

<%

Dim strUserAgent

strUserAgent = Request.ServerVariables("HTTP_USER_AGENT")

Response.Write "navigator.userAgent : " & strUserAgent

%>

S T E P - 2

- we need to identify the browser:

<%

If InStr(strUserAgent, "MSIE") Then 'If contain the "MSIE", which means the user is using Internet Explorer.

Response.Write "Internet Explorer"

Else

If InStr(strUserAgent, "Mozilla") Then 'If contain the "Mozilla", which means the browser is compatible with Netscape.

If InStr(strUserAgent, "Compatible;") = 0 'If not contain the "Compatible;", which means the browser is Netscape Navigator.

Response.Write "Netscape Navigator"

Else

Response.Write "Other"

End If

Else

Response.Write "Other"

End If

End If

%>

No comments: