How does it work?
In plain words, when somebody enters your site from a mobile device, this script executes itself recognizing that the user’s browser is in a mobile device and automatically redirects the user to the mobile site.
The used regular expression is not case-sensitive. That means that no matter if the browser reports with lower, capital, or mixed cases. If it is an iPhone, the code will be identified.
How can we make the site to redirect us every time we access it?
The user’s browser history will not record a new “entry” if we use location.replace instead of location.href. And this script does it. This means the user will not be able to go “back” to get the script executed again and get redirected again. It works as if the mobile site was the one the user visited right from the start. If clearer for the user, the better.
There are lots of variances for this script, a simple google search will lead you to hundreds of them.
So, if you are planning to have a mobile friendly site, please, make sure it has this script!
You can copy the script from here, remember to replace “http://landing.getcs.com/pca/mlanding.html” with the URL of your mobile friendly site, and it should work: