javascript - How can i set cookie for background changer code? -



javascript - How can i set cookie for background changer code? -

here code need set cookie.is body background image changer , want set cookies expire in x days! no matter if javascript or jquery cookies!

class="snippet-code-js lang-js prettyprint-override"><script> $(document).ready(function(){ $("li.one").click( function(){ $ ("body").removeclass('bg2 , bg3 , bg4 , bg5 , bg6 , bg7 ,bg8').addclass("bg1"); }); $("li.two").click( function(){ $ ("body").removeclass("bg1 , bg3 , bg4 , bg5 , bg6 , bg7 , bg8").addclass("bg2"); }); $("li.three").click( function(){ $ ("body").removeclass("bg1 , bg2 , bg4 , bg5 , bg6 , bg7 , bg8").addclass("bg3"); }); $("li.four").click( function(){ $ ("body").removeclass('bg1 , bg2 , bg3 , bg5 , bg6 , bg7 , bg8').addclass("bg4"); }); $("li.five").click( function(){ $ ("body").removeclass('bg1 , bg2 , bg3 , bg4 , bg6 , bg7 , bg8').addclass("bg5"); }); $("li.six").click( function(){ $ ("body").removeclass('bg1 , bg2 , bg3 , bg4 , bg5 , bg7 , bg8').addclass("bg6"); }); $("li.seven").click( function(){ $ ("body").removeclass('bg1 , bg2 , bg3 , bg4 , bg5 , bg6 , bg8').addclass("bg7"); }); $("li.eight").click( function(){ $ ("body").removeclass('bg1 , bg2 , bg3 , bg4 , bg5 , bg6 , bg7').addclass("bg8"); }); }); </script> class="snippet-code-html lang-html prettyprint-override"><ul id="foxycode-panel_bg_image"> <li class="one"><a href="#"></a></li> <li class="two"><a href="#"></a></li> <li class="three"><a href="#"></a></li> <li class="four"><a href="#"></a></li> </ul> ................ thanks!

if looking way set cookie n days. can utilize next function:

<script type="text/javascript"> function setcookie(cookiename,cookievalue,ndays) { var today = new date(); var expire = new date(); if (ndays==null || ndays==0) ndays=1; expire.settime(today.gettime() + 3600000*24*ndays); document.cookie = cookiename+"="+escape(cookievalue)+ ";expires="+expire.togmtstring(); } </script> , cookie, can utilize <script type="text/javascript"> function getcookie(cname) { var name = cname + "="; var ca = document.cookie.split(';'); for(var i=0; i<ca.length; i++) { var c = ca[i].trim(); if (c.indexof(name)==0) homecoming c.substring(name.length,c.length); } homecoming ""; } </script>

works perfect me.

javascript jquery cookies background

Comments

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -