用ASP来判断用户浏览器类型、版本以及操作系统的类型和版本,以前发过类似的检测程序,今天这个是另一ASP达人所写,希望对你的ASP编码有帮助作用,代码中包括两个函数:GetBrowser()为浏览器类型及版本检测,getsys()为操作系统类型及版本检测。
01
|
<%
|
02
|
'操作系统检测
|
03
|
function getsys()
|
04
|
vibo_soft=Request.ServerVariables("HTTP_USER_AGENT")
|
05
|
if instr(vibo_soft,"Windows NT 5.0") then
|
06
|
msm="Win 2000"
|
07
|
elseif instr(vibo_soft,"Windows NT 5.1") then
|
08
|
msm="Win XP"
|
09
|
elseif instr(vibo_soft,"Windows NT 5.2") then
|
10
|
msm="Win 2003"
|
11
|
elseif instr(vibo_soft,"4.0") then
|
12
|
msm="Win NT"
|
13
|
elseif instr(vibo_soft,"NT") then
|
14
|
msm="Win NT"
|
15
|
elseif instr(vibo_soft,"Windows CE") then
|
16
|
msm="Windows CE"
|
17
|
elseif instr(vibo_soft,"Windows 9") then
|
18
|
msm="Win 9x"
|
19
|
elseif instr(vibo_soft,"9x") then
|
20
|
msm="Windows ME"
|
21
|
elseif instr(vibo_soft,"98") then
|
22
|
msm="Windows 98"
|
23
|
elseif instr(vibo_soft,"Windows 95") then
|
24
|
msm="Windows 95"
|
25
|
elseif instr(vibo_soft,"Win32") then
|
26
|
msm="Win32"
|
27
|
elseif instr(vibo_soft,"unix") or instr(vibo_soft,"linux") or instr(vibo_soft,"SunOS") or instr(vibo_soft,"BSD") then
|
28
|
msm="类Unix"
|
29
|
elseif instr(vibo_soft,"Mac") then
|
30
|
msm="Mac"
|
31
|
else
|
32
|
msm="Other"
|
33
|
end if
|
34
|
getsys=msm
|
35
|
End Function
|
36
|
37
|
'浏览器类型及版本检测
|
38
|
function GetBrowser()
|
39
|
dim vibo_soft
|
40
|
vibo_soft=Request.ServerVariables("HTTP_USER_AGENT")
|
41
|
Browser="unknown"
|
42
|
version="unknown"
|
43
|
'vibo_soft="Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; TencentTraveler ; .NET CLR 1.1.4322)"
|
44
|
If Left(vibo_soft,7) ="Mozilla" Then '有此标识为浏览器
|
45
|
vibo_soft=Split(vibo_soft,";")
|
46
|
If InStr(vibo_soft(1),"MSIE")>0 Then
|
47
|
Browser="Microsoft Internet Explorer "
|
48
|
version=Trim(Left(Replace(vibo_soft(1),"MSIE",""),6))
|
49
|
ElseIf InStr(vibo_soft(4),"Netscape")>0 Then
|
50
|
Browser="Netscape "
|
51
|
tmpstr=Split(vibo_soft(4),"/")
|
52
|
version=tmpstr(UBound(tmpstr))
|
53
|
ElseIf InStr(vibo_soft(4),"rv:")>0 Then
|
54
|
Browser="Mozilla "
|
55
|
tmpstr=Split(vibo_soft(4),":")
|
56
|
version=tmpstr(UBound(tmpstr))
|
57
|
If InStr(version,")") > 0 Then
|
58
|
tmpstr=Split(version,")")
|
59
|
version=tmpstr(0)
|
60
|
End If
|
61
|
End If
|
62
|
ElseIf Left(vibo_soft,5) ="Opera" Then
|
63
|
vibo_soft=Split(vibo_soft,"/")
|
64
|
Browser="Mozilla "
|
65
|
tmpstr=Split(vibo_soft(1)," ")
|
66
|
version=tmpstr(0)
|
67
|
End If
|
68
|
If version<>"unknown" Then
|
69
|
Dim Tmpstr1
|
70
|
Tmpstr1=Trim(Replace(version,".",""))
|
71
|
If Not IsNumeric(Tmpstr1) Then
|
72
|
version="unknown"
|
73
|
End If
|
74
|
End If
|
75
|
GetBrowser=Browser &" "& version
|
76
|
End function
|
77
|
%>
|
上述两个函数均无需参数,直接调用即可返回结果。
热门源码