Java
1PublicBooleanJudgeismoblie (HttpServletRequest request) {2 BooleanIsmoblie =false; 3 //String[] mobileagents = {"iphone", "Android", "Phone", "mobile", "WAP", "NetFront", "Java", "Opera Mobi", "Opera Mini", "UC Web "," Windows CE "," Symbian "," series "," webOS "," Sony "," BlackBerry "," Dopod "," Nokia "," Samsung "," PalmSource "," XDA ", "Pieplus", "Meizu", "MIDP", "CLDC", "Motorola", "Foma", "DoCoMo", "Up.browser", "Up.link", "Blazer", "Helio", "Hosin", "H Uawei "," Novarra "," Coolpad "," webOS "," TechFaith "," PalmSource "," Alcatel "," Amoi "," Ktouch "," Nexian "," Ericsson "," Phi Lips "," Sagem "," wellcom "," Bunjalloo "," Maui "," Smartphone "," Iemobile "," Spice "," Bird "," zte-"," Longcos "," Pantech "," Gionee "," portalmmm "," Jig Browser "," Hiptop "," BenQ "," Haier "," ^LCT "," 320x320 "," 240x320 "," 176x220 "," the "" The "," acs-"," Alav "," Alca "," Amoi "," Audi "," Avan "," BenQ "," Bird "," Blac "," Blaz "," Brew "," Cell "," CLDC "," cmd-"," Dang "," doco "," Eri C "," Hipt "," Inno "," iPAQ "," Java "," Jigs "," KDDI "," Keji "," Leno "," Lg-c "," lg-d "," Lg-g "," lge-"," Maui "," Maxo "," MIDP ", "MITs", "MMEF", "Mobi", "mot-"," "Moto", "MWBP", "nec-", "Newt", "Noki", "oper", "palm", "pana", "Pant", "Phil", "Play", "Port", "ProX", "Qwap", "Sage", "Sams", "Sany", "sch-", "sec-", "Send", "Seri", "sgh-", "Shar", "sie-", "Siem", "Smal", "Smar", "Sony", "sph-", "symb", "t -mo "," Teli "," tim-"," Tosh "," tsm-"," Upg1 "," Upsi "," Vk-v "," Voda "," wap-"," Wapa "," Wapi "," Wapp "," WAPR "," Webc "," winw "," WINW "," XDA "," xda-"," Googlebot-mobile "};4String [] mobileagents = {"Android", "Android", "iphone", "iphone", "SymbianOS", "Windows Phone", "ipad", "ipad", "I Pod "," IPod "};5 if(Request.getheader ("user-agent")! =NULL) { 6System.out.println (Request.getheader ("User-agent"));7 for(String mobileagent:mobileagents) {8 if(Request.getheader ("User-agent"). toLowerCase (). IndexOf (mobileagent) >= 0) { 9Ismoblie =true; Ten Break; One } A } - } - returnIsmoblie; the}
Js
varIsPC =function(){ varUseragentinfo =navigator.useragent; varAgents = ["Android", "IPhone", "SymbianOS", "Windows Phone", "IPad", "IPod"]; varFlag =true; for(varv = 0; v < agents.length; v++) { if(Useragentinfo.indexof (agents[v]) > 0) {flag=false; Break; } } returnFlag; }
Java and JS to determine whether the request comes from the mobile side