删除cookies chrome扩展程序 [英] Delete cookies chrome extension
问题描述
我想自动删除特定域名上的所有cookie,因此我制作了一个扩展名。我可以查看域的cookie,但没有找到任何删除它们的方法。
这里是我的代码,函数eraseCookie被称为一次
有什么建议吗?
function eraseCookie(name){
document.cookie = name +'=;到期日=星期四,1970年1月1日00:00:01 GMT;';
$(document).ready(function(){
var cookies = document.cookie.split(;);
for(var i = 0; i< cookies.length; i ++)
{
window.alert(cookies [i]);
eraseCookie(cookies [i]。 split(=)[0]);
}
});
我也使用jquery,但是我没有看到问题!
{
name:Gapa,
version:0.1,
说明:,
browser_action:{
default_icon:sigla.png,
default_title:,
popup:hello。 html
,
content_scripts:[
{
matches:[*://*.google.ro/*],
js:[jquery-1.8.2.min.js,cookie_handler.js]
}
],
图标:{
128 :sigla.png},
权限:[
cookies,
标签,
*://*.google.ro/*
],
manifest_version:2
}
LE:
下面是我的脚本文件的外观:
$(document) .ready(function(){
var cookies = document.cook ie.split( ;);
for(var i = 0; i< cookies.length; i ++)
{
chrome.cookies.remove({url:.google.ro,name :cookies [i] .split(=)[0]},function(deleted_cookie){window.alert('deleted cookie')});
}
});
首先,您必须在清单中提供Cookie权限。
其次,Chrome会为您提供cookie api,其中删除功能已定位到:
chrome.cookies.remove(对象细节,函数回调);
您可以像这样使用它:
<$ ({url:http://domain.com,name:cookieName},函数(deleted_cookie){console.log(deleted_cookie) );});
尝试使用此选项来列出所选域的所有Cookie(内部删除功能会从此域中删除所有Cookie) :
chrome.cookies.getAll({domain:domain.com},function(cookies){
(var i = 0; i< cookies.length; i ++){
chrome.cookies.remove({url:http://domain.com+ cookies [i] .path,name:cookies [ i] .name});
}
});
在您的manifest.json中添加:
background:{
scripts:[background.js]
},
,并在background.js中包含提议的函数。
I want to delete all cookie on certain domain automatically so I have crafted an extension.I am able to view the cookies for the domain but I didn't find any method to delete them
Here is my code the function eraseCookie is just called one time
Any suggestions ?
function eraseCookie(name) {
document.cookie = name + '=; expires=Thu, 01 Jan 1970 00:00:01 GMT;';
}
$(document).ready(function() {
var cookies = document.cookie.split(";");
for (var i = 0; i < cookies.length; i++)
{
window.alert(cookies[i]);
eraseCookie(cookies[i].split("=")[0]);
}
});
I am also using jquery but I don't see a problem in that!
{
"name": "Gapa",
"version": "0.1",
"description": "",
"browser_action": {
"default_icon": "sigla.png",
"default_title": "",
"popup": "hello.html"
},
"content_scripts": [
{
"matches": ["*://*.google.ro/*"],
"js": ["jquery-1.8.2.min.js","cookie_handler.js"]
}
],
"icons": {
"128":"sigla.png" },
"permissions": [
"cookies",
"tabs",
"*://*.google.ro/*"
],
"manifest_version": 2
}
LE : Here is how my script file looks now:
$(document).ready(function() {
var cookies = document.cookie.split(";");
for (var i = 0; i < cookies.length; i++)
{
chrome.cookies.remove({"url": ".google.ro", "name":cookies[i].split("=")[0]}, function(deleted_cookie) { window.alert('deleted cookie') });
}
});
First of all you must provide cookies permission in your manifest.
Second of all Chrome provides you with cookies api where remove function is localted:
chrome.cookies.remove(object details, function callback);
You can use it like that:
chrome.cookies.remove({"url": "http://domain.com", "name": "cookieName"}, function(deleted_cookie) { console.log(deleted_cookie); });
Try using this to list all cookies for selected domains (inner delete function removes all cookies from this domain):
chrome.cookies.getAll({domain: "domain.com"}, function(cookies) {
for(var i=0; i<cookies.length;i++) {
chrome.cookies.remove({url: "http://domain.com" + cookies[i].path, name: cookies[i].name});
}
});
In your manifest.json add:
"background": {
"scripts": ["background.js"]
},
and in background.js you include proposed function.
这篇关于删除cookies chrome扩展程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!