开发者

Safari doesnt save cookie data but IE/FF does?

I'm stuck with this weird issue in Safari. I'm storing a user selection data in a cookie using javascript.

I create the cookie using following code -

document.cookie = cookieName +
           "=" + encodeURIComponent(cookieValue) +
           "; expires=" + jsDate.toGMTString();

and its read using -

var cookie = document.cookie;
    if(cookie.length !== 0){
         var theCookie=" "+document.cookie;
         var ind=theCookie.indexOf(" "+cookieName+"=");
         if (ind==-1) ind=theCookie.indexOf(";"+cookieName+"=");
         if (ind==-1 || cookieName=="") return "";
         var ind1=theCookie.indexOf(";",ind+1);
         if (ind1==-1) ind1=theCookie.length; 
         return unescape(theCookie.substring(ind+cookieName.length+2,ind1));}
        else { return '';}

This code works fine in Firefox and IE but when I access this cookie's data in Safari - an empty string is returned. The weird thing is, if i REPEAT my selection and try again, i can access the data. In other words, the first time i access my site, the cookie data is unavailable but in subsequent attempts the da开发者_StackOverflow社区ta is available!

To see this issue again, i have to clear Safari's cache, history and delete the cookies from the "Show cookies" section and reopen the browser.

Another observation - when i fail to read the cookie data, we can see the cookie when we look under Safari > Preferences > Security > Show cookies

ps: facing this with Safari version 4 & 5

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜