Solved

detecting if a visitor is on a mobile device

Posted on 2011-03-23
5
533 Views
Last Modified: 2012-05-11
Hi,

I am struggling to find a definative answer to my question which I know is well used.

Basically I have a flash file on my website.

I want to add some code to my vb.net page that can tell if the user is from a mobile device and if so just make the flash invisible and replace it with an image.

What is the best way to do this so I don't have to worry about specific devices etc like ihpone and so on.....?

Thanks in advance
0
Comment
Question by:scm0sml
  • 3
  • 2
5 Comments
 
LVL 6

Accepted Solution

by:
HyperBPP earned 500 total points
ID: 35199863
0
 

Author Comment

by:scm0sml
ID: 35199979
ok so if i wanted to do it in code rather than using the webconfig:
context.Request.ServerVariables["HTTP_USER_AGENT"] =

what would i need to check for just to see if it is a mobile device rather than worrying about the manufacturer etc as it is in the code behind that I will need my code to hide the image?
0
 
LVL 6

Expert Comment

by:HyperBPP
ID: 35200362
Surround the Flash content with an "if" statment similar to:

if(isMobileBrowser() = false) then
    <flash stuff here>
end if
0
 

Author Comment

by:scm0sml
ID: 35200509
You're missing my point.

What goes after the = in my previous post?
0
 
LVL 6

Expert Comment

by:HyperBPP
ID: 35200707
You are going to have to loop over several values to find out if the HTTP_USER_AGENT is a mobile device.  I personally would use a HashTable to store the values listed below, and use:

if(hashTableVar.containsKey(context.Request.ServerVariables["HTTP_USER_AGENT"]) = False) then
    ...Flash stuff...
end if


If HTTP_USER_AGENT is equal to any of the following values then it is a mobile device:

“midp”, “j2me”, “avant”, “docomo”,
“novarra”, “palmos”, “palmsource”,
“240×320¿, “opwv”, “chtml”,
“pda”, “windows ce”, “mmp/”,
“blackberry”, “mib/”, “symbian”,
“wireless”, “nokia”, “hand”, “mobi”,
“phone”, “cdm”, “up.b”, “audio”,
“SIE-”, “SEC-”, “samsung”, “HTC”,
“mot-”, “mitsu”, “sagem”, “sony”
, “alcatel”, “lg”, “eric”, “vx”,
“NEC”, “philips”, “mmm”, “xx”,
“panasonic”, “sharp”, “wap”, “sch”,
“rover”, “pocket”, “benq”, “java”,
“pt”, “pg”, “vox”, “amoi”,
“bird”, “compal”, “kg”, “voda”,
“sany”, “kdd”, “dbt”, “sendo”,
“sgh”, “gradi”, “jb”, “dddi”,
“moto”, “iphone”


This site has a listing of mobile browser user_agent strings:  http://www.zytrax.com/tech/web/mobile_ids.html.

0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question