0

So I have looked around and it seems like everything is deleting cookies using Javascript but AFTER they CREATED it. My question is how do I delete a cookie from a website stored on my computer using javascript.

Say I go to www.yahoo.com and I get a cookie named "apeaf" (real cookie from yahoo) path = / accessible to script = yes

So my question is how would I write a JS script to delete that cookie? I did not make it I just want to write a script that basically says

document.cookie = 'Name=apeaf ; Path=/; Domain=.www.yahoo.com; Expires=Thu,01 Jan 1970 00:00:01 GMT;';

but that is not deleting it.

mx0
  • 6,445
  • 12
  • 49
  • 54

1 Answers1

2

You cannot delete or read cookies from other websites via javascript (Unless you're doing it from a developer extension or through the console). If you're looking to do this in a development environment, I suggest using the Developer tools that are available in most modern browsers:

Blue
  • 22,608
  • 7
  • 62
  • 92
  • So there is no way to use Javascript to delete cookies? You said unless you are using developer tools but can javascript access that and still delete cookies? – greatsoccerman1 Jul 25 '18 at 17:31
  • Are you trying to delete cookies from your own website? @greatsoccerman1 – Blue Jul 25 '18 at 17:47
  • sort of i guess. So for this project i need to delete a cookie from my website but the server creates the cookie not the website. And the cookie determines which server you will connect to. so if i delete the cookie i can change which server the app will be on without restarting the app. – greatsoccerman1 Jul 25 '18 at 19:12
  • @greatsoccerman1 You need to ensure the path, name, domain, are correct. Plenty of examples: https://stackoverflow.com/questions/2144386/how-to-delete-a-cookie (If you're still having trouble, you need to post the cookie that was set, and give us a reproducible issue). – Blue Jul 25 '18 at 19:18
  • so basically if the client didn't create the cookie there is no way to delete it from the client? – greatsoccerman1 Jul 25 '18 at 19:47
  • So just wondering why can i go in a manually delete the cookies but not add some function to my computer to delete the cookies from my computer? – greatsoccerman1 Jul 25 '18 at 19:54