当前位置: 代码迷 >> ASP.NET >> 怎么判断网站是用手机端还是PC端访问的
  详细解决方案

怎么判断网站是用手机端还是PC端访问的

热度:9141   发布时间:2013-02-25 00:00:00.0
如何判断网站是用手机端还是PC端访问的
rt

谢谢!

------解决方案--------------------------------------------------------
userAgent
JScript code
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><HTML> <HEAD>  <TITLE> New Document </TITLE> </HEAD> <BODY>  <SCRIPT LANGUAGE="JavaScript">  <!--function detectOS(){      var sUserAgent = navigator.userAgent;     var isWin = (navigator.platform == "Win32") || (navigator.platform == "Windows");                                                                            var isMac = (navigator.platform == "Mac68K") || (navigator.platform == "MacPPC") || (navigator.platform == "Macintosh");     if(isMac) return "Mac";     var isUnix = (navigator.platform == "X11") && !isWin && !isMac;     if(isUnix) return "Unix";     var isLinux = (String(navigator.platform).indexOf("Linux") > -1);     if(isLinux) return "Linux";     if(isWin)     {          var isWin2K = sUserAgent.indexOf("Windows NT 5.0") > -1 || sUserAgent.indexOf("Windows 2000") > -1;         if(isWin2K) return "Win2000";         var isWinXP = sUserAgent.indexOf("Windows NT 5.1") > -1 || sUserAgent.indexOf("Windows XP") > -1;         if(isWinXP) return "WinXP";         var isWin2003 = sUserAgent.indexOf("Windows NT 5.2") > -1 || sUserAgent.indexOf("Windows 2003") > -1;         if(isWin2003) return "Win2003";     }      return "None"; }alert(detectOS())  //-->  </SCRIPT> </BODY></HTML>
  相关解决方案