How to add a cookie to save style selected by user Jquery -


i have styleswitcher added site , add cookie saves last style selected user. have code, guide me in process?

thanks reading!

i have code switch styles on site:

html call main style , main color

    <style type="text/css"> @import url("style.css");</style>     <link href="yellow.css" rel="stylesheet" type="text/css" title="yellow theme" /> 

then call scripts usual

    <script type="text/javascript" src="http://www.google.com/jsapi"></script>     <script type="text/javascript" src="script.js"></script> 

each button has this:

    <a class="colorbox colorred" href="?theme=red" title="red theme"><img src="red.png" width="x" height="x" /></a>     <a class="colorbox colorblack" href="?theme=black" title="black theme"><img src="black.png" width="x" height="x" /></a> 

now here script.js code:

    google.load("jquery", "1.5.2");     google.setonloadcallback(function()     {      // color changer     $(".colorblack").click(function(){         $("link").attr("href", "black.css");         return false;     });      $(".colorred").click(function(){         $("link").attr("href", "red.css");         return false;     });            }); 

something this? untested:

$(function() {      if($.cookie("style") !== null) {         $('link').attr('href', $.cookie("style"));     }      $('a').each(function() {         $(this).click(function(e) {             e.preventdefault();             var css = $(this).attr('href');             css = css.split('=');             $('link').attr('href', ''+ css[2] +'.css');             $.cookie("style", ""+ css[2] +".css", { path: '/', expires: 365 });         });     });  }); 

it require jquery cookie plugin.


Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -