Mobile Detection Script (Javascript redirect for iPhone / Android / Blackberry)

I struggled to find us a usable mobile javascript redirect - even StackOverflow's helpful crew were awash with geeky prejudice along the lines of "not all mobiles have javascript enabled"...
Almost all of the modern web requires javascript to be on, and if you're a) one those geeks who has it switched off or b) have a pre-Android/iPhone/Blackberry handset then you can try your luck with the main non-mobile site anyway.

So here goes - a short, quick, simple mobile detect + redirect script:


/* Klik Mobile Detection Script */
function touchAndGo(where) {
  var ua = navigator.userAgent.toLowerCase();
  if (ua.search("iphone") > -1 ||  ua.search("ipod") > -1 ||  ua.search("android") > -1 ||  ua.search("blackberry") > -1 || screen.width <= 480) {
    location.href=where;
  }
}
touchAndGo("http://touch.mysite.com/");

Comments

Rupesh said…
this mobile detection and redirection script is just awesome, you can get this one at below link :
codecanyon.net/item/mobredirect-mobile-detection-and-redirection/3630502

Popular posts from this blog

Installing LAMP Apache/MySQL/PHP on Chromebook/Chromebox

Installing Ubuntu Linux on your ChromeBox/ChromeBook

Changing your Mac OSX Terminal's default text editor