分享你我的心得.
共乘一片美好网络.

asp判断浏览器和操作系统的方法

用ASP来判断用户浏览器类型、版本以及操作系统的类型和版本。
代码中包括两个函数:GetBrowser()为浏览器类型及版本检测,getsys()为操作系统类型及版本检测。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
< %
'操作系统检测
function getsys()
vibo_soft=Request.ServerVariables("HTTP_USER_AGENT")
if instr(vibo_soft,"Windows NT 5.0") then
    msm="Win 2000"
elseif instr(vibo_soft,"Windows NT 5.1") then
    msm="Win XP"
elseif instr(vibo_soft,"Windows NT 5.2") then
    msm="Win 2003"
elseif instr(vibo_soft,"4.0") then
    msm="Win NT"
elseif instr(vibo_soft,"NT") then
    msm="Win NT"
elseif instr(vibo_soft,"Windows CE") then
    msm="Windows CE"
elseif instr(vibo_soft,"Windows 9") then
    msm="Win 9x"
elseif instr(vibo_soft,"9x") then
    msm="Windows ME"
elseif instr(vibo_soft,"98") then
    msm="Windows 98"
elseif instr(vibo_soft,"Windows 95") then
    msm="Windows 95"
elseif instr(vibo_soft,"Win32") then
    msm="Win32"
elseif instr(vibo_soft,"unix") or instr(vibo_soft,"linux") or instr(vibo_soft,"SunOS") or instr(vibo_soft,"BSD") then
    msm="类Unix"
elseif instr(vibo_soft,"Mac") then
    msm="Mac"
else
    msm="Other"
end if
getsys=msm
End Function
 
'浏览器类型及版本检测
function GetBrowser()
dim vibo_soft
vibo_soft=Request.ServerVariables("HTTP_USER_AGENT")
Browser="unknown"
version="unknown"
'vibo_soft="Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; TencentTraveler ; .NET CLR 1.1.4322)"
If Left(vibo_soft,7) ="Mozilla" Then '有此标识为浏览器
            vibo_soft=Split(vibo_soft,";")
            If InStr(vibo_soft(1),"MSIE")>0 Then
                Browser="Microsoft Internet Explorer "
                version=Trim(Left(Replace(vibo_soft(1),"MSIE",""),6))
            ElseIf InStr(vibo_soft(4),"Netscape")>0 Then
                Browser="Netscape "
                tmpstr=Split(vibo_soft(4),"/")
                version=tmpstr(UBound(tmpstr))
            ElseIf InStr(vibo_soft(4),"rv:")>0 Then
                Browser="Mozilla "
                tmpstr=Split(vibo_soft(4),":")
                version=tmpstr(UBound(tmpstr))
                If InStr(version,")") > 0 Then
                    tmpstr=Split(version,")")
                    version=tmpstr(0)
                End If
            End If
ElseIf Left(vibo_soft,5) ="Opera" Then
            vibo_soft=Split(vibo_soft,"/")
            Browser="Mozilla "
            tmpstr=Split(vibo_soft(1)," ")
            version=tmpstr(0)
End If
If version<>"unknown" Then
            Dim Tmpstr1
            Tmpstr1=Trim(Replace(version,".",""))
            If Not IsNumeric(Tmpstr1) Then
                version="unknown"
            End If
End If
GetBrowser=Browser &" "& version
End function
%>
赞(0)
未经允许不得转载:小叶白龙博客 » asp判断浏览器和操作系统的方法
分享到: 更多 (0)

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址