Reputation: 3779
I am in the process of wrapping up a mobile site and I need to give the user the option to switch from the mobile(jQuery mobile) site to the desktop version of the site. I am planning on using the code below for detection on both sides and then setting a cookie if the user makes the preference of one or the other site (mobile / desktop). I am curious to know best practice for this type of thing as I feel this will work well but not sure if there is a better way.
var isMobile = navigator.appVersion.toLowerCase().indexOf('mobile') > -1
Thanks in advance,
JN
Upvotes: 2
Views: 85
Reputation: 734
There are many ways to do it but because there are so many variations of user agents it can definitely be tricky. However, there is a nice script out there that solves this problem fairly elegantly. It also handles the cookie'ing that you touched on as well.
https://github.com/sebarmeli/JS-Redirection-Mobile-Site
Upvotes: 1