Home > Article > Backend Development > PHP vs. Javascript Detect code for Android devices via JavaScript or PHP
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 the code The code is as follows:
if(navigator.userAgent.match(/Android/i)) {
// Do something!
// Redirect to Android-site?
window.location = 'http://android.davidwalsh.name';
}
Copy the code The code is as follows:
if(strstr($_SERVER['HTTP_USER_AGENT'],'Android')) {
header('Location: http:/ /android.davidwalsh.name');
exit();
}
Copy the code The code is as follows :
RewriteCond %{HTTP_USER_AGENT} ^.*Android.*$
RewriteRule ^(.*)$ http://android.davidwalsh.name [R=301]
The above has introduced PHP and Javascript to detect the code of Android devices through JavaScript or PHP, including PHP and Javascript. I hope it will be helpful to friends who are interested in PHP tutorials.