First, jquery
var deviceAgent = navigator.userAgent.toLowerCase(); var agentID = deviceAgent.match(/(iphone|ipod|ipad|android)/); if(agentID.indexOf("iphone")>=0){ alert("iphone"); } if(agentID.indexOf("ipod")>=0){ alert("ipod"); } if(agentID.indexOf("ipad")>=0){ alert("ipad"); } if(agentID.indexOf("android")>=0){ alert("android"); }
<! Doctype HTML>
The second type of Java:
Enumeration typestr = request. getheadernames (); string S1 = request. getheader ("User-Agent"); If (s1.contains ("android") {system. out. println ("Android mobile client");} else if (s1.contains ("iPhone") {system. out. println ("iPhone mobile client");} else if (s1.contains ("iPad") {system. out. println ("iPad client");} else {system. out. println ("other clients ");}
Index. jsp:
<% @ Page Language = "Java" Import = "Java. util. *" contenttype = "text/html; charset = UTF-8" pageencoding = "UTF-8" %> <! Doctype HTML public "-// W3C // dtd html 4.01 transitional // en" "http://www.w3.org/TR/html4/loose.dtd"> <HTML>
In the second case, the test can generally meet the requirements. If you encounter a third-party browser such as UC browser, you may not be able to get it!
Python, PHP, Ror, And. Net can all use the second method!