javascript - If document.cookie is a string, why doesn't document.cookie = "" delete all of the relevant site's cookies? -


i think knowing answer me conceptualize relationship between cookies stored browser , document.cookie made available via dom.

document.cookie doesn't behave normally. browsers treat calls reading , writing document.cookie different calls object properties.

setting document.cookie doesn't set entire cookie string. instead, adds cookies. example:

alert(document.cookie); // existing cookie string "foo=bar; spam=eggs" document.cookie = "hello=world; lol=cats"; alert(document.cookie); // cookie string might "foo=bar; spam=eggs; hello=world; lol=cats" 

though order of cookies may vary, snippet still illustrates point. setting document.cookie sets cookies specified, doesn't remove cookie because it's not mentioned in new string. it'd easy make mistakes.

of course, i'm not totally sure why api built way. suspect things might different if writing cookie api today, , have read, write, delete, etc., functions. however, we've got.


Comments

Popular posts from this blog

c++ - Is it possible to compile a VST on linux? -

java - Output of Eclipse is rubbish -

jquery - Confused with JSON data and normal data in Django ajax request -