With the return of Steve Jobs and the release of iPad2, it seems that mobile development is becoming increasingly popular. This section describes how to detect the Android system, the biggest competitor to iOS.
JavaScript Judgment Method
Searching for Android words in the user agent string is the most convenient method:
- if(navigator.userAgent.match(/Android/i)) {
- // Do something!
- // Redirect to Android-site?
- window.location = 'http://android.davidwalsh.name';
- }
PHP Judgment Method
Similarly, we can use the strstr method in PHP to search for Android in the user agent:
- if(strstr($_SERVER['HTTP_USER_AGENT'],'Android')) {
- header('Location: http://android.davidwalsh.name');
- exit();
- }
In addition, you can use. htaccess to determine
We can use. htaccess to determine and respond to Android devices!
- RewriteCond %{HTTP_USER_AGENT} ^.*Android.*$
- RewriteRule ^(.*)$ http://android.davidwalsh.name [R=301]
In this way, you have mastered the detection methods of all three Android devices.
Http://article.yeeyan.org/view/56089/176760