JavaScript书签删除给定域中的所有Cookie [英] JavaScript bookmarklet to delete all cookies within a given domain

查看:190
本文介绍了JavaScript书签删除给定域中的所有Cookie的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在测试一个网页应用程式,将Cookie写入subdomain.thisdomain.com和其中的几个子资料夹。我正在寻找的JavaScript,我可以放入一个书签,将删除该子域下的所有cookie,无论它们存在的文件夹。



任何想法? / p>

解决方案

衍生自我的回答在这里

  javascript:new function(){var c = document。对于(var i = 0; i  -1?c [ i] .substr(0,e):c [i]; document.cookie = n +=; expires = Thu,01 Jan 1970 00:00:00 GMT;}}()

由于浏览器安全性问题,此操作只能在有权访问您要删除的所有Cookie的网页上执行时使用。 / p>

I am testing a web app that writes cookies to subdomain.thisdomain.com and several subfolders within that. I'm looking for JavaScript that I can put into a bookmarklet that will delete all cookies under that subdomain, regardless of the folder in which they exist.

Any ideas?

解决方案

Derived from my answer here:

javascript:new function(){var c=document.cookie.split(";");for(var i=0;i<c.length;i++){var e=c[i].indexOf("=");var n=e>-1?c[i].substr(0,e):c[i];document.cookie=n+"=;expires=Thu, 01 Jan 1970 00:00:00 GMT";}}()

Due to browser security issues, this will only work when executed while on a page that has access to all the cookies you want to delete.

这篇关于JavaScript书签删除给定域中的所有Cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆