This article is an example of how asp.net and JavaScript determine whether a cell phone is accessible. Share to everyone for your reference, specific as follows:
<summary>
///to Judge mobile phone users useragent
///</summary>
///<returns></returns>
private bool IsMobile ()
{
HttpContext context = HttpContext.Current;
If (context!= null)
{
HttpRequest request = context. Request;
if (request). Browser.ismobiledevice) return
true;
String mobileuseragent=system.configuration.configurationmanager.appsettings["Mobileuseragent"];
Regex Mobile_regex = new Regex (mobileuseragent);
if (string. IsNullOrEmpty (Request. useragent) | | Mobile_regex. IsMatch (Request. Useragent.tolower ()) return
true;
}
return false;
}
The following is the Web.config configuration inside the
Copy Code code as follows:
<add key= "mobileuseragent" value= "iphone|android|nokia|zte|huawei|lenovo|samsung|motorola|sonyericsson|lg| philips|gionee|htc|coolpad|symbian|sony|ericsson|mot|cmcc|iemobile|sgh|panasonic|alcatel|cldc|midp|wap|mobile| Blackberry|windows Ce|mqqbrowser|ucweb "/>
<script>
var system ={ Win:false, mac:false, xll:false };
Detection Platform
var p = navigator.platform;
System.win = P.indexof ("win") = = 0;
System.mac = P.indexof ("mac") = = 0;
system.x11 = (P = = "X11") | | (P.indexof ("Linux") = = 0);
Jump Statement
if (system.win| | system.mac| | SYSTEM.XLL)
{
alert (SYSTEM.MAC)
}
else
{
window.location.href= "mobile Access Address";
}
</script>
More interested readers of asp.net related content can view the site topics: "asp.net operation JSON tips summary", "asp.net string operation tips Summary", "ASP.net Operation XML Skills summary", "asp.net file Operation skills Summary", " asp.net Ajax Skills Summary topic and the "ASP.net cache operation skills Summary."
I hope this article will help you to ASP.net program design.