JavaScript で Cookie を作成しました。そのファイルで Cookie を確認して使用できます。同じドメイン内の別のページで同じ Cookie を表示して使用することができません。何が問題なのですか?
これがコードです
// Code for set Cookie
// Code for set Cookie
function setCookie(c_name,value,exdays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate() + exdays);
var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
document.cookie=c_name + "=" + c_value;
}
//Function to call setcookie. In this function I cookie is adding successfully and I can alert the value of the cartcounter cookie. It will be increment one by one for each click
function makeSure(skey,name){
var cartcounter=getCookie("cartcounter");
cartcounter=parseInt(cartcounter);
chk=0;
for(var i=1;i<=cartcounter;i++){
var ckey = getCookie(i+"_skey");
if(ckey==skey){
chk++;
}
}
if(chk==0){
cartcounter=cartcounter+1;
setCookie("cartcounter",cartcounter,365);
setCookie(cartcounter+"_skey",skey,365);
setCookie(cartcounter+"_name",name,365);
setCookie(cartcounter+"_val",$("#cnt_"+skey).val(),365);
alert(name+" added to your cart successfully.. ");
}
else
alert("You have already added "+name+" item to cart ");
}
// This is the code in another page to view the cookie. But it show only 0
var cartcounter=getCookie("cartcounter");
alert("Counter="+cartcounter);