I was looking for a way to do it myself. After accepting the code here, I found several problems (nothing special, just maybe mixing languages, which I do regularly). Here the modified version is fixed 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
Note that I did not declare two variables, I know that it is lazy, but since ASP is not Option Explicit, I find this a useful convenience.
Now it works like a charm on my mobile device discovery page:
<%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 this helps.
DIsFanJen
source share