Chrome doesn't delete session cookies

后端 未结 13 1673
有刺的猬
有刺的猬 2020-11-22 05:25

I\'m trying to set session cookie in javascript like this:

document.cookie = \'name=alex; path=/\'

But Chrome doesn\'t delete it even if I

相关标签:
13条回答
  • 2020-11-22 06:01

    Google chrome has a problem if you set and unset cookie improper way. This is php code. Thought this will give you idea.

    Set cookie

    setcookie('userLoggedIn', 1, 0, PATH);
    

    Wrong way and will not work (notice PATH is missing)

    setcookie('userLoggedIn', 0, time()-3600);
    

    Correct way fixes issue on google chrome

    setcookie('userLoggedIn', 0, time()-3600, PATH);
    
    0 讨论(0)
  • 2020-11-22 06:08

    A simple alternative is to use the new sessionStorage object. Per the comments, if you have 'continue where I left off' checked, sessionStorage will persist between restarts.

    0 讨论(0)
  • 2020-11-22 06:11

    This maybe because Chrome is still running in background after you close the browser. Try to disable this feature by doing following:

    1. Open chrome://settings/
    2. Click "Show advanced settings ..."
    3. Navigate down to System section and disable "Continue running background apps when Google Chrome is closed". This will force Chrome to close completely and then it will delete session cookies.

    However, I think Chrome should check and delete previous session cookies at it starting instead of closing.

    0 讨论(0)
  • 2020-11-22 06:11

    I had the same problem with "document.cookie" in Windows 8.1, the only way that Chrome deletes the cookie was shutting it from task manager (not a really fancy way), so I decided to manage the cookies from the backend or use something like "js-cookie".

    0 讨论(0)
  • 2020-11-22 06:11

    The solution would be to use sessionStorage, FYI: https://developer.mozilla.org/en-US/docs/Web/API/Window/sessionStorage

    0 讨论(0)
  • 2020-11-22 06:14

    This can be caused by having Chrome set to Continue where you left off.

    enter image description here

    Further reading

    • Bug report: Chrome is not deleting temporary cookies – i.e. not logging me out automatically when I close all browser Windows
    • Issue 128513 in Chromium: Session Cookies not cleared when Chrome processes closed
    • Issue 128567: Session only cookies don't delete
    0 讨论(0)
提交回复
热议问题