Skip to content

Instantly share code, notes, and snippets.

@brunobar79
Created November 8, 2012 17:59
Show Gist options
  • Select an option

  • Save brunobar79/4040419 to your computer and use it in GitHub Desktop.

Select an option

Save brunobar79/4040419 to your computer and use it in GitHub Desktop.
mobile redirect for dummies
<script>
// <![CDATA[
var mobile = (/iphone|ipod|android|blackberry|mini|windows\sce|palm/i.test(navigator.userAgent.toLowerCase()));
if (mobile) {
if(location.href.search("www.")!=-1){
location.href = location.href.replace("www.site.com/", "m.site.com/");
}else{
location.href = location.href.replace("site.com/", "m.site.com/");
}
}
}
// ]]>
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment