This section describes how to detect the Android system, the biggest competitor to iOS. This allows you to use JavaScript or PHP to detect Android devices.
This section describes how to detect the Android system, the biggest competitor to iOS. This allows you to use JavaScript or PHP to detect Android devices.
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:
The 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:
The 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!
The 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