Hi all.

I have got a code that detects the most mobile devices except Samsung Galaxy S3 (there may be other exceptions as well). Please advice how is it possible to detect the device Samsung Galaxy S3.

My code is:

<script type="text/javascript">            
    var isMobile = {
        Android: function() {
            return navigator.userAgent.match(/Android/i);
        },
        BlackBerry: function() {
            return navigator.userAgent.match(/BlackBerry/i);
        },
        iOS: function() {
            return navigator.userAgent.match(/iPhone|iPad|iPod/i);
        },
        Opera: function() {
            return navigator.userAgent.match(/Opera Mini/i);
        },
        Windows: function() {
            return navigator.userAgent.match(/IEMobile/i);
        },
        any: function() {
            return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Opera() || isMobile.Windows());
        }
    };
    if(isMobile.any()){
        alert("The device is mobile!");
    }
 </script>

Thank you.

Why don't you just alert the userAgent and find out.

  SAMSUNGALAXY S3: function() {
            return navigator.userAgent.match(/SAMSUNG GALAXY S3/i);
        },
        any: function() {
            return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() 
            || isMobile.Opera() || isMobile.Windows() || ismobile.SAMSUNGALAXY S3());
        }

may you have to edit your code with above code i am not tested it give a try all the best

How are you connected to the Galaxy?
Do you have a cable physically going from the micro-USB plug of the Galaxy to a USB port of a computer?

Don't forget to change the setting within the Galaxy itself. You have to tell it to connect as a media device, not just as a device whose battery needs charging.

I need to Specify that when the page is accessed from its default browser, it is not detected, but when accessing the page from Chrome, it is working.

Actually I need to implement a code into a site to re-direct users if they are connected from mobile devices. When we test the script, with most of the phones it is ok, and with Samsung S3 it is ok if accessing the page with Chrome.

The code:

alert(navigator.userAgent);

returns 'Mozilla/5.0 (X11;Linux x86_64) AppleWebKit/534.24 (KHTML, like Gecko) Chrome/11.0.696.34 Safari/534.24'.

What substring should I take from this string to show that the device is Android?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.