Android Detection with JavaScript

Tags: Android, JavaScript

Its time when your web applications should support Android as its one of the competitors in the mobile industry. The following JavaScript code searches the User Agent for "Android" and is the quickest method to detect whether the device is Android based.

    var ua = navigator.userAgent.toLowerCase();
    var isAndroid = ua.indexOf("android"); 
    if (isAndroid) 
        // Redirect to Android-site
        window.location = '';

That’s it!  Now you know which device is being used to surf your web application and you can change the way it works accordingly.

Add a Comment