I looked up how to delete cookies, and most of the links recommended setting the MaxAge to some large negative number, or the expiration date to January 1970. While this certainly works, it requires the client to refresh the page to have the cookies be deleted. Is there a way to remove the cookie immediately?
It should work on any browser. You could also punish them if they don’t buy putting a invisible div, preventing them to click by putting this in a div’s styles:
Just in case if they are on some really strong DNS and it won’t redirect (which would make for a bad one, btw) alert them or don’t allow them to click anymore.
I searched on my browser extensions store and found an extension that deletes the cookies immediately without reloading the site. Any idea how that would work?
I found this interesting thing on W3Schools. If you set the cookie key to nothing and then the expiration date to 1970 it’ll delete without reloading.
If you’re using Chrome, to view the source of an extension, go to chrome://extensions, toggle developer mode (top right) and click unpack extension, then choose the extension you want.
If you’re not using Chrome, I don’t know how to do that
Anyways the code the extension developer used was extremely complicated - I used a loop and some split() to grab all the cookie keys, set them all to "", and then appended max-age: -100 at the end so the cookie disappeared. In the end, w3schools was the most helpful as always