First, Javascript
[JavaScript]View Plaincopyprint?
[JavaScript] View plaincopyprint?View code slices to my Code slicevarDeviceAgent =navigator.userAgent.toLowerCase (); varAgentid = 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> <HTML> <Head> <Metaname= "Viewport"content= "initial-scale=1.0, User-scalable=no" /> <Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8"> <styletype= "Text/css">HTML{Height:100%}Body{Height:100%;margin:0px;padding:0px} </style> <Scripttype= "Text/javascript"> functionInitialize () {varuseragent=navigator.useragent; if(Useragent.indexof ('IPhone') != -1) {alert ("IPhone"); } Else if(Useragent.indexof ('IPad') != -1) {alert ("IPad"); } Else if(Useragent.indexof ('Android') != -1) {alert ("Android"); } Else{alert ("Other Platforms"); } } </Script> </Head> <Bodyonload= "Initialize ()"> </Body> </HTML>
The second type of Java:
[Java]View Plaincopyprint?
Enumeration Typestr = request.getheadernames (); = 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 client"); }
Entire page 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" > 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"); } %> </body>
These two methods test down, in general can meet the needs, encounter like the UC browser these third-party browsers, may not be allowed!
Source: http://blog.csdn.net/feng88724/article/details/7312827
[Mobile Web] How to differentiate mobile devices in the Web? (IPad, IPhone, Android)