Simple way to redirect user if Mobile

Javascript can detect screen size and redirect users if they are using mobile. I’ve found that checking the screen size and redirecting users based on that can cover 99% of the use cases rather than injecting some complicated browser detection javascript libraries.

The screen width of IPAD is 768px and screen width of a bigger mobile is 500px. So it would be safe to say that you anyone browsing the site using mobile phone would have a resolution lesser than 700px.

A simple script like that will work

if (screen.width <= 700) {
  window.location = "http://your-mobile-site";

Author: bpeh

Bernard Peh is a great passioner of web technologies and one of the co-founder of Website Design and Reviews. He works with experienced web designers and developers everyday, developing and designing commercial websites. He specialises mainly in SEO and PHP programming.