Welcome to WebmasterWorld Guest from

Forum Moderators: ocean10000

Message Too Old, No Replies

I am looking for the equivalent of this code in classic asp

1:23 pm on Sep 16, 2010 (gmt 0)

5+ Year Member

I have this code in ASP.net, but like to use something similar on older Classic ASP pages. I can't rename the pages from .asp to .aspx, too many out there and spidered in the search engines. I am looking to display specific messages to mobile users and other messages to non-mobile users. Any input is appreciated. Thanks

<script language="VB" runat="server">
Sub Page_Load(sender as Object, e as EventArgs)
if Request.Browser.Browser = "AppleMAC-Safari" then
Response.Write("not mobile")

end if

End Sub
1:27 pm on Sep 16, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member

Here is roughly the equivalent in Classic ASP, I've used IE6 as an example:
dim strUA
strUA = Request.ServerVariables("HTTP_USER_AGENT")
if inStr(strUA, "MSIE 6.0") > 0 then
Response.Write("IE 6 Booooh!")
Response.Write("Other Browser")
end if
1:59 pm on Sep 16, 2010 (gmt 0)

5+ Year Member

Thanks. It seems to be working. I see that the function inStr looks for the wording in the HTTP_USER_AGENT, but question - what does the "> 0" do exactly? Thanks
2:03 pm on Sep 16, 2010 (gmt 0)

5+ Year Member

if anybody else wants working code, this seems to work. I've tested it on my Android phone too.

dim strUA
strUA = Request.ServerVariables("HTTP_USER_AGENT")

response.write Request.ServerVariables("HTTP_USER_AGENT") & "<br/><br/>"

if inStr(strUA, "Mobile Safari") > 0 or inStr(strUA, "Android") > 0 then

Response.Write("Other Browser")
end if
2:13 pm on Sep 16, 2010 (gmt 0)

5+ Year Member

p.s. You'd need to add some code for Blackberry/ Windows Mobile / and other mobile devices. I just covered what I believe most of my users would be on.
3:12 pm on Sep 16, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member

what does the "> 0" do exactly?

inStr will give the index of the found string as a return value. If it is zero, then the string has not been found.

- InStr("abcdefgh", "d") will return 4
- InStr("abcdefgh", "z") will return 0
4:13 pm on Sep 16, 2010 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month

In Classic Asp there is a Browser Capabilities Com object supplied by Microsoft, using that with Browser.ini [browsers.garykeith.com] supplied by Gary and updated very very often. With these two you should be able to identify most of the common mobiles and web browsers out there currently.

Example of the Browser Capabilties Com Object in Classic Asp.

' create an instance of the Browser Capabilities component
Set browserdetect = Server.CreateObject("MSWC.BrowserType")

' find some properties of the browser being used to view this page

' send some output to the web browser
response.write ("Browser: " & browser & "<BR>")
response.write ("Version: " & version & "<BR>")
response.write ("Majorver: " & majorver & "<BR>")
response.write ("Minorver: " & minorver & "<BR>")
response.write ("Platform: " & platform & "<BR>")
response.write ("Supports frames: " & frames & "<BR>")
response.write ("Supports tables: " & tables & "<BR>")
response.write ("Supports cookies: " & cookies & "<BR>")
response.write ("Supports JavaScript: " & javascript & "<BR>")
5:24 pm on Sep 16, 2010 (gmt 0)

5+ Year Member

Cool. I don't have complete control of the server to install this, so Marcel's solution will work too, for now. Thanks again guys.

Featured Threads

Hot Threads This Week

Hot Threads This Month