javascript - Is Document.cookie's setter asynchronous in web browsers? -


i under impression document.cookie = "mysessioncookie=mysessiontoken" not set right away in browser.

more precisely, here's situation:

  • i logged in.
  • i want logout using javascript.
  • so set, instance document.cookie = "mysessioncookie=; path=/; expires=thu, 01 jan 1970 00:00:00 gmt".
  • then call window.location.reload() confirm have been logged out.

it works, but, quite often, appears browser not have enough time set new cookie value before calling window.location.reload().

unless doing wrong in code, behaviour suggests document.cookie = "value" not executed on same stack (so, might not asynchronous itself, has unpredictable behaviour when used rest of code).

so, question is, document.cookie = "value" executed on different stack?

indeed, pointed out @charlietfl comment original question, document.cookie setter set cookie right away.

my real problem had error in program, not paying attention fact browsers set cookie's "path" based on current uri when no path provided along cookie value when setting cookie using javascript.

for example, if 1 wants clear session uris @ example.com while viewing resource @ http://example.com/fake-resource, 1 must explicitly write:

document.cookie = "sessiontoken=;path=/;expires=thu, 01 jan 1970 00:00:00 gmt"

else (i.e. if path=/ omitted) browser create second cookie example.com/fake-resource, such main cookie continue exist.


Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -