Deleting Style switcher cookie
Hi I want to add to this style switcher (below code) one extra function var but don't know how or where to insert it. The code works great by switching between 2 sylesheet wide.css and boxed.css.
I want to add to it that when any stylesheet is selected.. a cookie name "bg_pattern" reset or removed. I have that cookie being stored by another script for the page background pattern. So basically I want the use to have the background pattern gone when they switch page width.
Code:
- function getCookie(css_width)
- {
- if (document.cookie.length>0)
- {
- c_start=document.cookie.indexOf(css_width + "=");
- if (c_start!=-1)
- {
- c_start=c_start + css_width.length+1;
- c_end=document.cookie.indexOf(";",c_start);
- if (c_end==-1) c_end=document.cookie.length;
- return unescape(document.cookie.substring(c_start,c_end));
- }
- }
- return "";
- }
- function setCookie(css_width,value,expiredays)
- {
- var exdate=new Date();
- exdate.setDate(exdate.getDate()+expiredays);
- document.cookie=css_width+ "=" +escape(value)+
- ((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
- }
- $(document).ready(function() {
- // Wide
- $("#css-wide").click(function() {
- $("link.css-width[rel=stylesheet]").attr({href : "css/wide.css"});
- setCookie('csspref', 'wide');
- });
- // Boxed
- $("#css-boxed").click(function() {
- $("link.css-width[rel=stylesheet]").attr({href : "css/boxed.css"});
- setCookie('csspref', 'boxed');
- });
- var $cssPref = getCookie('csspref');
- if ($cssPref.length > 0)
- {
- $('#css-' + $cssPref).trigger('click');
- }
- });