Manual swith back to normal Website on mobile Device using wurfl

43 Views Asked by At

I can't get into it. Please give me a hint. There is a website with device-detection with wurfl - the javascript method. The condition looks like this:

if(!WURFL.is_mobile){
$('body').addClass('mobile'); //Do the stuff for mobile website
} else {
$('body').addClass('no-mobile'); // Do the stuff for no-mobile normal website
};

Now we want to put a button on mobile Version to switch back to normal (no-mobile) Website manualy. But the website needs to be reloaded without care of the orginal wurfl-condition, because there are some images and html inserted with javascrit on the normal (no-mobile) Version. I don't know how to do this.

1

There are 1 best solutions below

2
jdmdevdotnet On BEST ANSWER

When the button is pressed to manually go to mobile or desktop, you can set a cookie like so:

document.cookie = "forceMobile=true";

then just read the cookie in your if statement like so:

function getCookie(cname) {
    var name = cname + "=";
    var decodedCookie = decodeURIComponent(document.cookie);
    var ca = decodedCookie.split(';');
    for(var i = 0; i <ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0) == ' ') {
            c = c.substring(1);
        }
        if (c.indexOf(name) == 0) {
            return c.substring(name.length, c.length);
        }
    }
    return "";
}

if(!WURFL.is_mobile && !getCookie("forceMobile")) ...

More info here