how to delete cookie in jquery at the time of browser closing?

前端 未结 4 924
無奈伤痛
無奈伤痛 2020-12-19 10:09

I have created a cookie by using jQuery. I want to delete the cookie with jQuery when the browser closes. How do I do this?

I\'ve written the following script:

4条回答
  •  时光说笑
    2020-12-19 10:35

    If you want delete cookie when you close browser than you should set a session cookie, which automatically expires when browser closed. But if you want delete cookie when you close a tab than you should use window.unload and window.beforeunload events, write a function to delete necessary cookies and attach to these events.

提交回复
热议问题