Use JavaScript or PHP to detect the code of the Android device. With the return of Steve Jobs and the release of iPad2, it seems that mobile development is becoming increasingly popular. Here we will list some detection methods that can be used in the Android system, the biggest competitor of iOS, 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
Bytes. Here we will list some methods to detect the Android system, the biggest competitor to iOS...