SoFunction
Updated on 2025-04-09

How to determine whether to access a mobile phone in javascript

This article describes the method of judging whether to access a mobile phone by javascript. Share it for your reference, as follows:

/// <summary>
///Judge mobile user UserAgent/// </summary>
/// <returns></returns>
private bool IsMobile()
{
  HttpContext context = ;
  if (context != null)
  {
    HttpRequest request = ;
    if ()
      return true;
    string MobileUserAgent=["MobileUserAgent"];
    Regex MOBILE_REGEX = new Regex(MobileUserAgent);
    if (() || MOBILE_REGEX.IsMatch(()))
      return true;
  }
  return false;
}

The following is the configuration

Copy the codeThe code is 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"/>
&lt;script&gt;
var system ={  win : false,  mac : false,  xll : false  };
//Detection platformvar p = ;
 = ("Win") == 0;
 = ("Mac") == 0;
system.x11 = (p == "X11") || (("Linux") == 0);
//Jump statementif(||||)
{
  alert()
}
else
{
  ="Mobile access address";
}
&lt;/script&gt;

For more information about relevant content, please view the topic of this site:Summary of operation json skills》、《Summary of string operation techniques》、《Summary of operating XML skills》、《Summary of file operation skills》、《Ajax tips summary topic"and"Summary of cache operation skills》。

I hope this article will be helpful to everyone's programming.