admin管理员组文章数量:1026989
I've been researching all over the place and I can't find anything. I find it hard to believe that I'm the first person to think about trying to do this, but I wonder if it's even possible.
I want to clear cookies, app cache, local storage, everything associated with a site using a bookmarklet that I can leave on my toolbar.
Is that possible?
I've been researching all over the place and I can't find anything. I find it hard to believe that I'm the first person to think about trying to do this, but I wonder if it's even possible.
I want to clear cookies, app cache, local storage, everything associated with a site using a bookmarklet that I can leave on my toolbar.
Is that possible?
Share Improve this question asked Apr 22, 2015 at 19:37 user4154355user4154355 2- You can use Firecookie, addons.mozilla/en-US/firefox/addon/firecookie – Rahul Tripathi Commented Apr 22, 2015 at 19:39
- I want to do a lot more than just clear cookies, so I don't think that is what I'm looking for. – user4154355 Commented Apr 27, 2015 at 13:07
1 Answer
Reset to default 7It is possible, and it is actually really easy to implement a simple solution.
It can be done following these steps:
- Create a bookmark and give it a descriptive name. For example: "Clear Storage".
- Change the URL so it is like
javascript:(function(){ [YOUR CODE] })();
- Replace
[YOUR CODE]
with one line of JavaScript that does the desired clearing.
For example:
To clear the local storage, use
localStorage.clear();
. The bookmark URL would be like:javascript:(function(){ localStorage.clear() })();
or just
javascript:localStorage.clear();
To delete cookies, use any of the solutions on this question. I opted for Craig Smedley's solution because it is already a one liner (and it was ready for a bookmarklet). The bookmark URL would be like:
javascript:(function(){ document.cookie.split(";").forEach(function(c) { document.cookie = c.replace(/^ +/, "").replace(/=.*/, "=;expires=" + new Date().toUTCString() + ";path=/"); }) })();
Now, to make multiple of these operations just with one click on the bookmark, just concatenate them (with only one javascript:
). For example, a URL for the bookmark that clears local storage and delete cookies would be like:
javascript:(function(){ localStorage.clear();var c = document.cookie.split("; "); for (i in c) { document.cookie =/^[^=]+/.exec(c[i])[0]+"=;expires=Thu, 01 Jan 1970 00:00:00 GMT"; }; })();
You just need to find the code that you like the most or better fits your needs, and save it on the bookmark. As it will probably be too large for the bookmark size, you may want to place the code in a file somewhere and apply it as described on this ment.
You can see a demo of a bookmark that deletes the localStorage on this JSFiddle.
I've been researching all over the place and I can't find anything. I find it hard to believe that I'm the first person to think about trying to do this, but I wonder if it's even possible.
I want to clear cookies, app cache, local storage, everything associated with a site using a bookmarklet that I can leave on my toolbar.
Is that possible?
I've been researching all over the place and I can't find anything. I find it hard to believe that I'm the first person to think about trying to do this, but I wonder if it's even possible.
I want to clear cookies, app cache, local storage, everything associated with a site using a bookmarklet that I can leave on my toolbar.
Is that possible?
Share Improve this question asked Apr 22, 2015 at 19:37 user4154355user4154355 2- You can use Firecookie, addons.mozilla/en-US/firefox/addon/firecookie – Rahul Tripathi Commented Apr 22, 2015 at 19:39
- I want to do a lot more than just clear cookies, so I don't think that is what I'm looking for. – user4154355 Commented Apr 27, 2015 at 13:07
1 Answer
Reset to default 7It is possible, and it is actually really easy to implement a simple solution.
It can be done following these steps:
- Create a bookmark and give it a descriptive name. For example: "Clear Storage".
- Change the URL so it is like
javascript:(function(){ [YOUR CODE] })();
- Replace
[YOUR CODE]
with one line of JavaScript that does the desired clearing.
For example:
To clear the local storage, use
localStorage.clear();
. The bookmark URL would be like:javascript:(function(){ localStorage.clear() })();
or just
javascript:localStorage.clear();
To delete cookies, use any of the solutions on this question. I opted for Craig Smedley's solution because it is already a one liner (and it was ready for a bookmarklet). The bookmark URL would be like:
javascript:(function(){ document.cookie.split(";").forEach(function(c) { document.cookie = c.replace(/^ +/, "").replace(/=.*/, "=;expires=" + new Date().toUTCString() + ";path=/"); }) })();
Now, to make multiple of these operations just with one click on the bookmark, just concatenate them (with only one javascript:
). For example, a URL for the bookmark that clears local storage and delete cookies would be like:
javascript:(function(){ localStorage.clear();var c = document.cookie.split("; "); for (i in c) { document.cookie =/^[^=]+/.exec(c[i])[0]+"=;expires=Thu, 01 Jan 1970 00:00:00 GMT"; }; })();
You just need to find the code that you like the most or better fits your needs, and save it on the bookmark. As it will probably be too large for the bookmark size, you may want to place the code in a file somewhere and apply it as described on this ment.
You can see a demo of a bookmark that deletes the localStorage on this JSFiddle.
本文标签: javascriptBookmarklet for clearing appcachecookieslocalstorageStack Overflow
版权声明:本文标题:javascript - Bookmarklet for clearing appcachecookieslocalstorage? - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745669128a2162351.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论