javascript - Bookmarklet for clearing appcache/cookies/localstorage? -


i've been researching on place , can't find anything. find hard believe i'm first person think trying this, wonder if it's possible.

i want clear cookies, app cache, local storage, associated site using bookmarklet can leave on toolbar.

is possible?

it possible, , easy implement simple solution.

it can done following these steps:

  1. create bookmark , give descriptive name. example: "clear storage".
  2. change url javascript:(function(){ [your code] })();
  3. replace [your code] 1 line of javascript desired clearing.

for example:

  • to clear local storage, use localstorage.clear();. bookmark url like:

    javascript:(function(){ localstorage.clear() })(); 

    or just

    javascript:localstorage.clear(); 
  • to delete cookies, use of solutions on question. opted craig smedley's solution because 1 liner (and ready bookmarklet). bookmark url like:

    javascript:(function(){ document.cookie.split(";").foreach(function(c) { document.cookie = c.replace(/^ +/, "").replace(/=.*/, "=;expires=" + new date().toutcstring() + ";path=/"); }) })(); 

now, make multiple of these operations 1 click on bookmark, concatenate them (with 1 javascript:). example, url bookmark clears local storage , delete cookies like:

javascript:(function(){ localstorage.clear();var c = document.cookie.split("; "); (i in c) { document.cookie =/^[^=]+/.exec(c[i])[0]+"=;expires=thu, 01 jan 1970 00:00:00 gmt"; }; })(); 

you need find code or better fits needs, , save on bookmark. large bookmark size, may want place code in file somewhere , apply as described on comment.

you can see demo of bookmark deletes localstorage on this jsfiddle.


Comments

Popular posts from this blog

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - UML - How would you draw a try catch in a sequence diagram? -

c++ - No viable overloaded operator for references a map -