javascript - Cookie is set twice; how to remove the duplicate? -
so have website uses cookie remember current layout state across visits. working great until added facebook 'like' button site generates links allow users share ui state (a little confusing not relevant problem).
the problem when visit site via 1 of these facebook links second copy of layout cookie seems created (as in, see 2 cookies same name , different values). wouldn't terrible except value of duplicate cookie appears stuck, coupled fact when user returns site browser remembers stuck value instead of set value (so it's kind of there's "good" cookie can still work with, , "bad" 1 cannot, , browser likes remember "bad" cookie instead of "good" cookie). breaks layout tracking/remembering functionality.
so there 2 questions here:
- how stop happening/why happening in first place?
- how fix things users have stuck cookie (i know pick new name cookie, i'd rather finding way unstick stuck cookie)?
if use chrome's developer console after visiting page in stuck state, can see document.cookie (formatting added readability):
layoutstate=[{'id':6,'x':8,'y':1525,'z':4,'url':'undefined'}, {'id':1,'x':625,'y':709,'z':2,'url':'undefined'}, {'id':2,'x':8,'y':37,'z':3,'url':'undefined'}, {'id':3,'x':625,'y':1179,'z':5,'url':'undefined'}, {'id':4,'x':626,'y':37,'z':1,'url':'undefined'}, {'id':5,'x':626,'y':357,'z':1000000,'url':'http://m.xkcd.com/303/'}]; wibiyanotification1=1; wibiyanotification213286=213286; wibiyanotification213289=213289; wibiya756904_unique_user=1; jsessionid=donthijackmeplease; wibiyaprofile={"toolbar":{"stat":"max"},"apps":{"openapps":{}},"connectusernetworks":[null,null,null,null,null,null]}; wibiyaloads=59; layoutstate=[{'id':6,'x':8,'y':1525,'z':4,'url':'undefined'}, {'id':1,'x':625,'y':709,'z':2,'url':'undefined'}, {'id':2,'x':8,'y':37,'z':3,'url':'undefined'}, {'id':3,'x':625,'y':1179,'z':5,'url':'undefined'}, {'id':4,'x':626,'y':37,'z':1,'url':'undefined'}, {'id':5,'x':626,'y':357,'z':6,'url':'http://m.xkcd.com/303/'}]" ignore wibiya cookies , jsessionid. stuck cookie first 'layoutstate' instance, , 1 can still manipulate in javascript second 'layoutstate' instance. here if change things around:
layoutstate=[{'id':6,'x':8,'y':1525,'z':4,'url':'undefined'}, {'id':1,'x':625,'y':709,'z':2,'url':'undefined'}, {'id':2,'x':8,'y':37,'z':3,'url':'undefined'}, {'id':3,'x':625,'y':1179,'z':5,'url':'undefined'}, {'id':4,'x':626,'y':37,'z':1,'url':'undefined'}, {'id':5,'x':626,'y':357,'z':1000000,'url':'http://m.xkcd.com/303/'}]; wibiyanotification1=1; wibiyanotification213286=213286; wibiyanotification213289=213289; wibiya756904_unique_user=1; jsessionid=donthijackmeplease; wibiyaprofile={"toolbar":{"stat":"max"},"apps":{"openapps":{}},"connectusernetworks":[null,null,null,null,null,null]}; wibiyaloads=59; layoutstate=[{'id':1,'x':8,'y':39,'z':1000000,'url':'undefined'}] the second 'layoutstate' has correct information want browser remember. browser remembers value of first instance.
i've tried unsetting cookie entirely, causes second instance disappear, nothing seems rid of first instance. same behavior in major browsers (chrome, firefox, ie), makes me suspect must doing fundamentally wrong here, i'm not sure is.
you can view site here. or click here access via facebook link (should generate stuck cookie). appreciated.
update:
so steps reliably reproduce error follows:
- visit site via facebook-style link
- make changes layout, , close tab.
- visit site via normal url.
- your layout initial visit should correctly remembered, change things around , refresh page. when page reloads, changes no longer remembered.
i've noticed revisiting site via facebook-style url able clear/reset stuck cookie. it's browser keeping separate cookie each url path, or something, , not allowing root page access cookie set on other url path. thought might able fix explicitly setting path=/ on cookie, no dice.
update 2:
i've found if set both path , domain of cookie different behavior in browsers:
- firefox -
works correctly now, hooray!worked correctly once, broke, boo! - chrome - no change
- ie - seems keeping separate cookies each url, facebook-style url remembers 1 state, , standard url remembers different state. both update correctly , independently of each other. kind of funky, still way better stuck/broken state.
dude(tte), there inconsistencies, , bug, in cookie setter.
1. make sure path , domain correctly set
the path , domain should same both clearing cookie , setting it. see code here:
document.cookie = c_name + "=; expires=fri, 31 dec 1999 23:59:59 gmt;"; and compare to:
var c_value=escape(value) + "; expires=" + exdate.toutcstring(); + "; path=/spring; domain=aroth.no-ip.org"; you see setter has both of them, deleter doesn't. bring chaos.
2. oh, , nasty semicolon
that second line of code quoted above, has semicolon introduced in middle of string concatenation expression. right after exdate.toutcstring(). kill it. kill it…now.
at least on google chrome, managed run correctly, if set breakpoint @ json = "[" + json + "]"; , modify setcookie before executed.
p/s: bizzare debugging experience, managed set 4 layoutstate cookies, fiddling path & domain.
Comments
Post a Comment