[Mobile Web] How does one identify mobile devices on the web? (IPAD, iPhone, Android)

Source: Internet
Author: User

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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.