从经典ASP检测移动用户代理并在会话启动时重定向

Kei*_*ler 6 mobile user-agent asp-classic

我想检测一个移动用户代理,并在会话开始时在经典ASP应用程序中重定向它们.有谁知道一个很好的方法来解决这个问题?

小智 11

我一直在寻找一种方法来做到这一点.在这里已经获得代码后,我发现了一些问题(没有什么特别的,可能只是混合语言,我经常做的事情).这是针对Classic ASP更正的更改版本.

 Function Is_Mobile()
  Set Regex = New RegExp
  With Regex
    .Pattern = "(up.browser|up.link|mmp|symbian|smartphone|midp|wap|phone|windows ce|pda|mobile|mini|palm|ipad)"
    .IgnoreCase = True
    .Global = True
  End With
  Match = Regex.test(Request.ServerVariables("HTTP_USER_AGENT"))
  If Match then
    Is_Mobile = True
  Else
    Is_Mobile = False
  End If
End Function
Run Code Online (Sandbox Code Playgroud)

注意我没有声明这两个变量,我知道它很懒,但是因为ASP不是Option Explicit我觉得它很方便.

现在,这就像我的移动检测页面上的魅力一样,如下所示:

<%If Is_Mobile() then%>
  <META NAME="viewport" CONTENT="initial-scale = 0.6, user-scalable = no">
  <LINK REL="stylesheet" TYPE="text/css" HREF="/CSS/Mobile.css" />
<%Else%>
  <LINK REL="stylesheet" TYPE="text/css" HREF="CSS/Default.css" />
<%End If%>
Run Code Online (Sandbox Code Playgroud)

希望有所帮助.


Cod*_*ust 9

看一眼:

http://mobiforge.com/developing/story/lightweight-device-detection-asp

sub is_mobile()
  Dim Regex, match
  Set Regex = New RegExp
     With Regex
        .Pattern = "(up.browser|up.link|mmp|symbian|smartphone|midp|wap|phone|windows ce|pda|mobile|mini|palm|ipad)"
        .IgnoreCase = True
        .Global = True
      End With
   match = Regex.test(Request.ServerVariables("HTTP_USER_AGENT"))
   If match
      return True
   Else
      return False
   End If
End Sub
Run Code Online (Sandbox Code Playgroud)

**免责声明:*代码可能不起作用,因为我没有测试它的方法和经典ASP的小知识.