βρηκα λιγο κωδικα στο ιντερνετ για την αποθηκευση και ανακτηση cookies. Την αποθηκευση την κανω επιτυχως, αλλα δεν μπορω να τα ανακτησω επιτυχώς, απο άλλη σελίδα ομως, αν και βρισκεται και αυτή παρακάτω στο "μονοπάτι", στο οποίο δηλώνω το cookie ως valid.
Πιο συγκεκριμενα:
Χρησιμοποιω τη μεθοδο setCookie με το valid μονοπατι hardcoded. Η μεθοδος οριζεται στο "/home/kostas/9sem/hci/profiles/profile_user.html" και ισυει στο μονοπατι "/home/kostas/9sem/hci/"
Code: Select all
function setCookie(cookieName,cookieValue,expiration)
{
expirationDate=new Date();
expirationDate=expirationDate.valueOf()+expiration*24*60*60*1000;
expirationDate=new Date(expirationDate);
expires=";expires="+expirationDate.toGMTString();
path=";path="+x.href;
theCookie=cookieName+"="+escape(cookieValue)+path+expires;
document.cookie=theCookie;
}
Code: Select all
...
if (getCookie("married").value=="true")
{
window.open(x.href+"profile_wife.html","_self")
}
else
...
function getCookie(c_name)
{
var parent=window.parent.parent.document;
if (parent.cookie.length>0)
{
c_start=document.cookie.indexOf(c_name+"=")
if (c_start!=-1)
{
c_start=c_start+c_name.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 ""
}