Device detection can be very complicated. There are entire businesses based on correctly identifying the user’s device. Luckily for us to poor to afford such services there is another way to do device detection which doesn’t require us to re-invent the wheel.
One important thing to note is that only the index page does detection. If the user wants, we allow them to navigate to the desktop page on their phone. This is important, since most desktop sites have more features than their mobile counterparts. If the user isn’t able to achieve their goal on the mobile site and you don’t allow them to go to the desktop site, they might not come back.
The key part of the detection script, detectmobilebrowser.js, is towards the end. There it needs a link to go if it successfully detects a mobile browser. In my case it is phone.html. The demo code only detects mobile phones, not tablets. There are instructions on how to change the detection code to also detect tablets here.
To try the detection code for yourself, click the link below then select
For your own site, I recommend that you download the detection code from Detect Mobile Browsers. No telling when the code may get updated again. Also, if you use the detection code in your business, please consider giving Chad a donation to encourage him to keep it updated.