Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I am trying to implement a cookie to apply to all pages of my locally developed site (http://localhost888/develop). For some reason, I cannot get it to work by adding 'path /'. Below is the code I am currently using:

Here is the full code being used:

$(document).ready(function(){ 
var wrap = $('#viewMode'), 
viewMode = $.cookie( 'view-mode' ); 
wrap.children().hide(); 

$('.js-view-mode').on( 'click', 'a',function( e ){ 
e.preventDefault(); 
var t = $(this), 
type = t.attr('href'); 

if( t.parent().hasClass('s') ) return; 

t.parent().addClass('s') 
.siblings().removeClass('s'); 

var lheight = $("#viewMode").height(); 
if(lheight != 0){ 
$("#viewMode").css("height",lheight+"px"); 
} 
wrap.children().fadeOut(); $(type).delay(500).fadeIn(function(){ 
$("#viewMode").css("height","auto"); 
}); 

viewMode = $.cookie( 'view-mode', type ); 

}); 

if ( viewMode ) { 
$('.js-view-mode a[href='+ viewMode +']').trigger('click'); 
} else { 
$('.js-view-mode li:first a').trigger( 'click' ); 
} 

});

I have attempted to add the following to line 3 without success:

viewMode = $.cookie( 'view-mode', {path: '/'} ); 
share|improve this question
add comment

1 Answer

$.cookie('the name') is made for cookie reading. So, $.cookie('the name', the options) isn't good.

To create a cookie, with or without options, the syntax is $.cookie('the_cookie', 'the_value', { opt1: foo, opt2: bar, ... });

share|improve this answer
 
So, how could I transfer this viewMode = $.cookie( 'view-mode' ); to that successfully? What is the_value? –  N-WS Jun 14 '13 at 20:23
 
viewMode = $.cookie( 'view-mode' ); to get it. $.cookie( 'view-mode' , type, {path:"\"}); to set it –  TCHdvlp Jun 17 '13 at 8:08
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.