-1

I'm sure this gets asked a lot, but I also know things change quite frequently, so I am wondering what the current best way to do a simple mobile detection and redirection for a site is.

I'm not going to be able to cover all phones, but I'd like to at least get iphones and androids.

Thanks

Steve Beans
  • 83
  • 2
  • 13
  • "Best" might be too subjective. Can you talk about the technology you are using? – Kamil Sindi Nov 28 '11 at 18:40
  • These posts might be helpful: http://stackoverflow.com/questions/1005153/auto-detect-mobile-browser-via-user-agent and http://stackoverflow.com/questions/8176037/standard-practices-in-detecting-mobile-devices-and-feeding-pages-in-php-and-jque – Kamil Sindi Nov 28 '11 at 18:41
  • I googled "htaccess detect mobile browser" and got some promising hits. – JimmyPena Dec 07 '11 at 20:42

1 Answers1

0
<script type="text/javascript">
    function checkBrowser(){
        var str=navigator.appVersion; 
        var patt1=/Android/;
        var patt2=/iPhone/;
        if(str.match(patt1) || str.match(patt2)){
            window.location="http://m.yoursite.com";
        }
    }
</script>

then on the body-tag put onload="checkBrowser();"

it's a very simple way to do it, but i'm sure there plenty more ways.. hope it helps :)

Zencode.dk
  • 1,374
  • 1
  • 8
  • 12