Solved

detecting if a visitor is on a mobile device

Posted on 2011-03-23
5
534 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
custom authorization on controller action and HTML in asp.net mvc 1 57
orderby list (from Json) 1 44
c#, datatable, aspx 4 53
EF5 How do I stop pre-compiled views? 8 54
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

751 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