Skip to content Skip to sidebar Skip to footer

Jquery Custom Background Through A Cookie

I'm making background changing script for my site. Everything works fine except the cookie which should store the required value. I'm using jQuery 1.3. IE 8 says: 'object doesn't s

Solution 1:

I've converted your code to a more efficient, and syntactically valid JavaScript code.

functionimages(which){
    var image = /^t\d+/i.test(which) ? images[which.substr(1)-1] : null;
    if(image !== null) {
        $.cookie("html_img", image, {expires:7})
    } else {
        image = $.cookie("html_img");
        if(!image) image = images[0]; //If the image doesn't exist, use default=0
    }
    $('html').css("background-image", image);
}

$(document).ready(function(){
    images(); //Load image default from cookie
}

//If you want to change the image+cookie: images("t2");

Solution 2:

May be your "cookie plugin" script is not imported correctly? Can you give more details on the error you get. Use Firebug for Firefox or Chrome Dev tools to get a better error trace.

Post a Comment for "Jquery Custom Background Through A Cookie"