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:
Copy codeThe Code is as follows:
If (navigator. userAgent. match (/Android/I )){
// Do something!
// Redirect to Android-site?
Window. location = 'HTTP: // android. Davy. name ';
}
PHP Judgment Method
Similarly, we can use the strstr method in PHP to search for Android in the user agent:
Copy codeThe Code is as follows:
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!
Copy codeThe Code is as follows:
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.
Link: http://article.yeeyan.org/view/56089/176760