views:

775

answers:

1

Hey there,

I'm developing a mobile version of a website. I'm currently using this Javascript to detect and redirect the user:

if((navigator.userAgent.match(/iPhone/i)) || 
                (navigator.userAgent.match(/Android/i)) ||
                (navigator.userAgent.match(/iPod/i))) 
        { 
        window.location = "http://sitename.com/m/";
    }

Works fine with iPhone and iPod, but no success with Android. I'm using the Android Emulator within Eclipse. I don't have an Android gadget to actually test it.

Am I doing something wrong? Anyone having the same issue?

+3  A: 
if((navigator.userAgent.match(/iPhone/i)) || 
                (navigator.userAgent.match(/Android/i)) ||
                (navigator.userAgent.match(/iPod/i))) 
        { 
        location.replace("http://sitename.com/m/");
    }

I used this code and it works on iphone/itouch and android phones/devices.

JP
Thank you very much, sir. :)
Vitor