With the return of Steve Jobs and the release of iPad 2, it seems that the topic of mobile development is becoming more and more popular. Here are some detection methods that can be used on Android, the biggest competitor of iOS.
JavaScript Judgment Method
Searching for Android words in the user agent string is the easiest way:
Copy code The code is as follows:
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 to search for user in PHP Whether there is Android in the agent:
Copy code The code is as follows:
if(strstr($_SERVER['HTTP_USER_AGENT'], 'Android')) {
header('Location: http://android.davidwalsh.name');
exit();
}
In addition, you can pass .htaccess to determine
We can use .htaccess to determine and respond to Android devices!
Copy code The code is as follows:
RewriteCond %{HTTP_USER_AGENT} ^.*Android.*$
RewriteRule ^(.*)$ http://android.davidwalsh.name [R=301]
This way You’ve got all three ways to detect Android devices.
Original link: http://article.yeeyan.org/view/56089/176760
http://www.bkjia.com/PHPjc/323077.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/323077.htmlTechArticleWith the return of Steve Jobs and the release of iPad2, it seems that the topic of mobile development is becoming more and more popular. Here are some detection methods that can be used on the Android system, the biggest competitor of iOS...