javascriptjquerywurfl

Manual swith back to normal Website on mobile Device using wurfl


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.


Solution

  • 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