Reputation: 878
I'm using code to redirect mobile devices that are under 699 pixels wide to go to our mobile site. This method utilizes JavaScript and cookies and follows some basic logic:
skipmobile
is set to 1Redirect only if skipmobile
is not 1, and your mobile device is listed below and under 699 pixels wide.
//{{Full Site Code}} Only run logic if cookies are enabled.
if(navigator.cookieEnabled){
//If the cookie skipmobile is already set do not redirect to mobile.
if (document.location.search.indexOf("skipmobile") >= 0) {
document.cookie = "skipmobile=1";
}
//If the device is one of the types listed below and is under 699 pixels wide, redirect to the mobile site.
else if (((/Android|webOS|iPhone|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) && screen.width < 699)
&& document.cookie.indexOf("skipmobile") == -1)
{
document.location = "'.MOBILE_SITE.$direct.'";
}
}
On the mobile site I simply have a link like the following that someone can click to set the cookie
http://www.example.com?skipmobile=1
This code works properly for me and most people, but we are having customers saying When they click the full site link it sends them right back to the mobile site. According to the code this means they do have cookies enabled but their cookie isn't getting set.
Is there something I need to do to this code that's missing?
UPDATE: So this problem is a bit of an oddball. One of our employees is having the issue as well so we at least have a phone to test on. We have a live site and a dev site. It works for him of we go to the dev site and redirect but it doesn't for the live...
Does this help anyone come up with conclusions? The code is the same on both sites.
Upvotes: 0
Views: 66
Reputation: 978
You should try deleting all cookies
related to your site beforehand, as this should clear up any problems. This is a link to a great function that should do this for you:
You could also put that you don't want it to cache for a while in the headers (using the cache control var) to make sure that if the phone is storing any problems these are removed
Upvotes: 1