If a user surfs to my site I want to display a message if he using Android phone. My website is http://website.com
How can I do this?
I have tried this but not succeeded:
var ua = navigator.userAgent.toLowerCase();
var isAndroid = ua.indexOf("android") > -1; //&& ua.indexOf("mobile");
if(isAndroid) {
// Do something!
// Redirect to Android-site?
window.location = 'http://android.davidwalsh.name';
}
PHP get_browser() Function echo $_SERVER['HTTP_USER_AGENT']; $browser = get_browser(); print_r($browser);
You can detect Android user agent using PHP and Javascript also :
$ua = strtolower($_SERVER['HTTP_USER_AGENT']);
if(stripos($ua,'android') !== false) { // && stripos($ua,'mobile') !== false) {
echo "your message";
}
var ua = navigator.userAgent.toLowerCase();
var isAndroid = ua.indexOf("android") > -1; //&& ua.indexOf("mobile");
if(isAndroid) {
// Do something!
alert('Your message');
}
For PHP:
$isAndroid = (strpos($_SERVER['HTTP_USER_AGENT'], 'Android') !== false);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With