Posts

Showing posts from October, 2011

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/");