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 Android, the biggest competitor to iOS. The JavaScript judgment method is the easiest way to search for Android words in the useragent string: 1.if( navigator. userAgent. matc
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 Android, the biggest competitor to iOS. The JavaScript judgment method is the easiest way to search for Android words in the user agent string: 1. if (navigator. userAgent. matc
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 of the Android systems that can be the biggest competitor in iOSDetectionMethod.
JavaScript Judgment Method
Searching for Android words in the user agent string is the most convenient method:
1.if(navigator.userAgent.match(/Android/i)) {
2.// Do something!
3.// Redirect to Android-site?
4. window.location ='http://android.davidwalsh.name';
5. }
PHP Judgment Method
Similarly, 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: http://android.davidwalsh.name');
3.exit();
4. }
In addition, you canPass. Htaccess to determine
We can use. htaccess to determine and respond to AndroidDevice!
1. RewriteCond %{HTTP_USER_AGENT} ^.*Android.*$
2. RewriteRule ^(.*)$ http://android.davidwalsh.name [R=301]
In this way, you have mastered all three androidDeviceOfDetectionMethod.