简体   繁体   English

在页面刷新时删除cookie

[英]Delete cookies on page refresh

How do I delete cookies via JavaScript when you refresh a page ? 刷新页面时如何通过JavaScript删除cookie? I wanted to do this using the event onbeforeunload . 我想使用onbeforeunload事件来执行此操作。

Why you want to remove a cookie before it has a chance to be sent back to the server is beyond me, but here you go: 为什么要在有机会被发送回服务器之前删除cookie是超出我的,但是在这里你去:

window.onbeforeunload = function(e) {
    document.cookie = 'cookiename=; expires=' + d.toGMTString() + ';';
};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM