Redirect mobile users to another page – r/web_design

Congrats, you’re not using a “mobile” device. (or have javascript disabled)

donkey-kong-handheld

Why? /u/Rogerss93 asked, and it’s something that can be done within minutes without too much garbage.

Yeah yeah, there’s tons of reasons to NOT do stuff like this, but I really hate it when people tell you all the stuff completely unrelated and can’t answer the actual question. I mean I once asked on a homebrewers forum how you’d go about brewing a zero carb beer and I got exactly zero useful replies, but a gazillion people telling me why cutting out carbs is a bad idea for my health. On a fucking beer website FFS.

Anyhoo, I don’t care why you want to do it, here’s (probably) the simplest way to do it:

<script>
  if (screen.width <= 800) {
    window.location = "http://ashsimmonds.com/2016/06/02/congrats-youre-on-a-mobile-device/";
  }
</script>

Which for anyone drunker than me just means if your device’s screen width is less than 800px then we’ll send you somewhere else. As tech improves this won’t work so well, but you get the gist, just modify to your needs, it’s a dumb hack anyhoo. Sure, there’s a gazillion other ways to do it probably more eloquently and with fallbacks and blah blah, but fuck it this is just a quick hack that can be implemented and tested within minutes for a personal site.

If you are still here on mobile, you should have been re-directed to:

–> http://ashsimmonds.com/2016/06/02/congrats-youre-on-a-mobile-device/

Let me know if you’re here but on a mobile device un-redirected on the original reddit post:

–> https://www.reddit.com/r/web_design/comments/4m6bxr/how_to_go_about_displaying_a_message_for_any/d3swzxq

Pics: | 10867

You may also like...