我想要检测移动用户代理,并在经典的ASP应用程序中启动会话时重定向它们。有没有人知道做这件事的好方法?
发布于 2010-05-15 02:05:31
看一下:
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 Then
      return True
   Else
      return False
   End If
End Sub*免责声明:代码可能无法工作,因为我没有方法来测试它,也几乎不了解经典的ASP。
发布于 2011-08-10 07:13:12
我正在寻找一种方法自己来做这件事。在阅读了这里的代码后,我发现了一些问题(没什么特别的,可能只是混合了语言,这是我经常做的事情)。这是修改后的经典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请注意,我没有声明这两个变量,我知道它很懒,但由于ASP不是Option显式的,我发现它是一个有用的便利。
这在我的移动检测页面上就像是一个护身符,如下所示:
<%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%>希望这能有所帮助。
发布于 2012-12-12 15:41:41
更新以支持android
Function 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|Android|BlackBerry|iPhone|iPod|Palm|Symbian)"
        .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 Functionhttps://stackoverflow.com/questions/2836203
复制相似问题