JKirchartz

Web Yinzer

Better Mobile Redirect

Here is a simple reusable javascript redirect that uses the Mobile Link Discovery Spec which describes a link tag that tells the browser where to find an Alternate for Hand-Held devices: <link href="< Mobile URI >" media="handheld" rel="alternate">. The script is detecting user-agents, which is “evil” but not every site needs or wants the whole Responsive Design bundle, and that has it’s problems. Sometimes you just gotta redirect, try using the link tag with the script below:

Then you’d have html like this:

And away you go… I’m only testing for iPhone, iPad, Android, Blackberry, and WebOs. They run the market right now so I don’t feel too bad for leaving out the fray, if you’re logging your visitors user agents you can tweak the regex as needed.