简体   繁体   English

关闭页面时不会删除cookie?

[英]cookies are not deleted when page close?

在此处输入图片说明
i was create cookie (page load counting) whenever page load and then next delete cookies whenever close the window 每当页面加载时我都会创建cookie(页面加载计数),然后每当关闭窗口时就删除cookie

my problem : cookies are not deleted 我的问题 :cookie不会被删除

mycode: http://jsfiddle.net/Y3xs7/6 mycode: http //jsfiddle.net/Y3xs7/6

Edit: i remove expire date but no luck 编辑:我删除过期日期,但没有运气




将此代码写在script标签的任何地方

window.onbeforeunload=clear_cookie;

You set the cookie to expire after one month. 您将Cookie设置为在一个月后过期。

var futdate = new Date()
var expdate = futdate.getTime()
expdate += 3600000 * 24 *30  //expires in 1 hour (ed note: actually one MONTH)
futdate.setTime(expdate)

var newCookie="pageCount="+counter
newCookie += "; expires=" + futdate.toGMTString()
window.document.cookie=newCookie

Persistent cookies (those with specific expiration dates) are not deleted when the browser closes. 当浏览器关闭时,永久性cookie(具有特定到期日期的cookie)不会被删除。

If you don't give the cookie an expiration date, it becomes a session cookie, which is deleted when the browser closes. 如果您没有给cookie赋予有效期,它将成为一个会话cookie,当浏览器关闭时,它将被删除。

Also note that as of Chrome 19 and Firefox 3 , session cookies aren't deleted if the browser's startup mode option is "continue where I left off." 另请注意,从Chrome 19Firefox 3开始 ,如果浏览器的启动模式选项为“从我上次中断的地方继续”,则不会删除会话Cookie。

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

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