Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

detecting if a visitor is on a mobile device

Posted on 2011-03-23
5
Medium Priority
?
550 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 2000 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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying 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

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses

782 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