Header Ads

Find Mobile Device Using C# and Javascript

In this tutorial,I written few code lines in C# and Javascript to check whether visitors are browsing your website by mobile device such as Android,iPhone, iPad, iPod,SymbianOS, BlackBerry, Samsung, Nokia, SonyEricsson, Symbian, Windows CE, webOS and WAP



Find Mobile Device Using C#



string UserAgent = Request.UserAgent.ToString();
UserAgent = UserAgent.ToLower();
if (UserAgent.Contains("iphone") || UserAgent.Contains("symbianos") || UserAgent.Contains("ipad") || UserAgent.Contains("ipod") || UserAgent.Contains("android") || UserAgent.Contains("blackberry") || UserAgent.Contains("samsung") || UserAgent.Contains("nokia") || UserAgent.Contains("windows ce") || UserAgent.Contains("sonyericsson") || UserAgent.Contains("webos") || UserAgent.Contains("wap") || UserAgent.Contains("motor") || UserAgent.Contains("symbian"))
   {
  Response.Write("Go with Mobile Device!!!");
   }
 else
   {
  Response.Write("Go with normal browser!!!");
   }

Find Mobile Device Using Javascript


<script language="javascript" type="text/javascript">
var useragent = navigator.userAgent;
useragent = useragent.toLowerCase();
if (useragent.indexOf('iphone') != -1 || useragent.indexOf('symbianos') != -1 || useragent.indexOf('ipad') != -1 || useragent.indexOf('ipod') != -1 || useragent.indexOf('android') != -1 || useragent.indexOf('blackberry') != -1 || useragent.indexOf('samsung') != -1 || useragent.indexOf('nokia') != -1 || useragent.indexOf('windows ce') != -1 || useragent.indexOf('sonyericsson') != -1 || useragent.indexOf('webos') != -1 || useragent.indexOf('wap') != -1 || useragent.indexOf('motor') != -1 || useragent.indexOf('symbian') != -1 )
        {
  alert("Go with Mobile Device!");
 } 

 else 

 {
  alert("Go with normal browser!");
 }
   </script> 

No comments:



Powered by Blogger.