I'd like to detect a mobile user agent and redirect them when the session starts in a classic ASP app. Does anyone know a good way to pull this off?
I was looking for a way to do this myself. After taking the code already here I found a few issues (nothing special, just probably mixing languages, a thing I do regularly). Here's the altered version corrected for 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
Notice I didn't declare the two variables, I know it's lazy but as ASP isn't Option Explicit I find it a useful convenience.
This is now working like a charm on my page for mobile detection, as follows:
<%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%>
Hope that helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With