homepage Welcome to WebmasterWorld Guest from 54.163.91.250
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Microsoft / Microsoft IIS Web Server and ASP.NET
Forum Library, Charter, Moderators: ocean10000

Microsoft IIS Web Server and ASP.NET Forum

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




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

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("mobile")
else
Response.Write("not mobile")

end if


End Sub
</script>

 

marcel




msg:4202739
 1:27 pm on Sep 16, 2010 (gmt 0)

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!")
else
Response.Write("Other Browser")
end if

hal12b




msg:4202762
 1:59 pm on Sep 16, 2010 (gmt 0)

Marcel,
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

hal12b




msg:4202763
 2:03 pm on Sep 16, 2010 (gmt 0)

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("mobile")
else
Response.Write("Other Browser")
end if
%>

hal12b




msg:4202768
 2:13 pm on Sep 16, 2010 (gmt 0)

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.

marcel




msg:4202796
 3:12 pm on Sep 16, 2010 (gmt 0)

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.

ie.
- InStr("abcdefgh", "d") will return 4
- InStr("abcdefgh", "z") will return 0

Ocean10000




msg:4202844
 4:13 pm on Sep 16, 2010 (gmt 0)

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
browser=browserdetect.Browser
version=browserdetect.Version
majorver=browserdetect.Majorver
minorver=browserdetect.Minorver
platform=browserdetect.Platform
frames=browserdetect.Frames
tables=browserdetect.Tables
cookies=browserdetect.Cookies
javascript=browserdetect.JavaScript

' 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>")
%>

hal12b




msg:4202886
 5:24 pm on Sep 16, 2010 (gmt 0)

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.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Microsoft / Microsoft IIS Web Server and ASP.NET
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved