last day (16 days later) » 

7:14 PM
0
A: Switch stylesheets and remember the one selected using jquerie.cookie.js

Gaurav KalyanFollow these step to create custom layout according to user cookie:- Create a function which read the cookie and change the default.css function readCookieCSS(){ if($.cookie('styleSheet') === null || $.cookie('styleSheet')==undefined) { /*Do nothing*/ } else{ $...

 
Thanks for your help but i can't manage to make it work..since the jquery cookie plugin is already included in my file ,i have added your two pieces of code after my jquery example and edited the default.css name from your example, but no results. What am i doing wrong? Thank you.
 
You have defined the functions properly but you are not calling these functions. The first function readCookieCSS() will be called upon $(document).ready(function({...});. The second function saveCSSinCookie(CSS_FILE_NAME) will be called whenever you are changing the stylesheet. Please, suggest how are you changing the stylesheet so that second function can be added to it.
 
Sorry but i don't understand what do you mean by "suggest how are you changing the stylesheet" ..My stylesheets are changing via my jquery code ( the select box is generated via that code ) .
 
I got it, your are using change event in the "#css-selector" to update/ change the stylesheet. I have updated my code and declared where you have to call the functions, give them a try. :)
 
I'm lost :) .Please put all your code (if i don't ask too much ),including mine all together on jsfiddle.I'm a newbie on jquery i must say. Billion thanks again.
 
7:14 PM
Creating a fiddle is bit tough if we are dealing with cookies and changing stylesheet as it is not supported by jsfiddle. Please try to find the errors you getting and share it here. So a solution can be found out.
 
I didn't expected to have it working already, i just wanted to see the full code how it looks like,cause i don't know were to insert your edits..
 
I have updated code added the fiddle link in the code. Please see it and try it.
 
Almost done.Thank you very much sir. I can see the cookie saved but it doesn't activate the selected stylesheet anymore ( it doesn't change the colors anymore ) and when i refresh the page the "select color" text is visible again.Any ideea?
 
7:27 PM
@Eddi cool :). No need to call me sir, call me Gaurav. Step 1, i.e. setting up the cookie has been done and you are able to access the cookie also so great. Now you have to look forward to step 2 i.e. changing the style sheet. As we are able to set the cookie that means you are calling the function correctly. This means error lies here in this code $('link[href="default.css"]').attr('href',$.cookie('styleSheet')); . Try to see whether you able select the link properly
You can see the following example for selecting the link:- stackoverflow.com/questions/7846980/…
 
8:12 PM
Sorry for the late answer..
I already changed your default.css example with the right url for my stylesheet but still is not working
So default.css is actually the link for the default stylesheet in case none of the existing stylesheets are selected, right?
 
 
2 hours later…
10:19 PM
I just saw a difference of code and i don't think is because of the wrong url if default.css..For example in my original jquery code i have .bind('change',function(){
$('link[rel*=jquery]').remove();
$('head').append('<link rel="stylesheet jquery" href="'+$(this).val()+'" type="text/css" />');
});
and in yours is .bind('change',function(){
saveCSSinCookie($(this).val());
});
So once i insert this line: $('head').append('<link rel="stylesheet jquery" href="'+$(this).val()+'" type="text/css" />');
}); after your code: saveCSSinCookie($(this).val()); .........is working but again the selected css is not saved
 

  last day (16 days later) »