Detecting Android devices via JavaScript or PHP

Source: Internet
Author: User
Tags garbage collection

With the return of jobs, IPad2 's release seems to be getting hotter on the mobile side of the development topic. Here's a list of some of the biggest competitors in iOS-the Android (Android) system detection method.

JavaScript Judgment method

Searching for the Android word in the user agent string is the most time-saving method:

  1. if (Navigator.userAgent.match (/android/i)) {
  2. Do something!
  3. Redirect to Android-site?
  4. window.location = ' ';
  5. }

How to Judge PHP

Again, we can use the Strstr method in PHP to search for Android in the user agent:

  1. if (strstr ($_server[' http_user_agent '], ' Android ')) {
  2. Header (' Location: ');
  3. Exit ();
  4. }

In addition, you can use the. htaccess to judge

We can use. htaccess to judge and respond to Android devices!

  1. Rewritecond%{http_user_agent} ^.*android.*$
  2. Rewriterule ^ (. *) $ [r=301]

So you have all the three kinds of detection methods for Android devices.

Original link:

"Edit Recommendation"

    1. Deep understanding of the closure characteristics of JavaScript
    2. JavaScript cross-domain summarization and solutions
    3. Developing mobile applications using JavaScript
    4. Discussion on the evolution of garbage collection algorithm in PHP 5
    5. 1-minute perfect installation of the latest Centos+nginx+php-fpm+mysql
"Responsible editor: Chen Yu new TEL: (010) 68476606"

Related Article

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: 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.