Home Page
  • May 05, 2024, 06:23:09 am *
  • Welcome, Guest
Please login or register.

Login with username, password and session length
Advanced search  

News:

Official site launch very soon, hurrah!



Post reply

Warning: this topic has not been posted in for at least 120 days.
Unless you're sure you want to reply, please consider starting a new topic.

Note: this post will not display until it's been approved by a moderator.

Name:
Email:
Subject:
Message icon:

Attach:
(Clear Attachment)
(more attachments)
Restrictions: 10 per post, maximum total size 8192KB, maximum individual size 5120KB
Note that any files attached will not be displayed until approved by a moderator.
Verification:
Type the letters shown in the picture
Listen to the letters / Request another image

Type the letters shown in the picture:
Please stop spamming. Your spam posts are moderated and will never be displayed on the internet. What is eighty-eight minus eighty-six (spell out the answer):
Пожалуйста, прекратите спамить. Ваши спам-сообщения модерируются и никогда не будут отображаться в Интернете. What color is grass.:

shortcuts: hit alt+s to submit/post or alt+p to preview


Topic Summary

Posted by: Dakusan
« on: September 28, 2009, 05:32:06 am »

Original post for Erasing Website Cookies can be found at https://www.castledragmire.com/Posts/Erasing_Website_Cookies.
Originally posted on: 11/12/08

This erases all cookies on the current domain (in the “ / ” path)

JavaScript:

function ClearCookies() //Clear all the cookies on the current website
{
   var MyCookies=document.cookie; //Remember the original cookie string since it will be changing soon
   var StartAt=0; //The current string pointer in MyCookies
   do //Loop through all cookies
   {
      var CookieName=MyCookies.substring(StartAt, MyCookies.indexOf('=', StartAt)).replace(/^ /,''); //Get the next cookie name in the list, and strip off leading white space
      document.cookie=CookieName+"=;expires=Thu, 01-Jan-1970 00:00:01 GMT; path=/"; //Erase the cookie
      StartAt=MyCookies.indexOf(';', StartAt)+1; //Move the string pointer to the end of the current cookie
   } while(StartAt!=0)
}

I went a little further with the script after finishing this to add a bit of a visual aspect.
The following adds a textarea box which displays the current cookies for the site, and also displays the cookie names when they are erased.

<input type=button value="Clear Cookies" onclick="ClearCookies()">
<input type=button value="View Cookies" onclick="ViewCookies()">
<textarea id=CookieBox style="width:100%;height:100%"></textarea>
<script type="text/javascript">
function ViewCookies() //Output the current cookies in the textbox
{
   document.getElementById('CookieBox').value=document.cookie.replace(/;/g,';\n\n');
}

function ClearCookies() //Clear all the cookies on the current website
{
   var CookieNames=[]; //Remember the cookie names as we erase them for later output
   var MyCookies=document.cookie; //Remember the original cookie string since it will be changing soon
   var StartAt=0; //The current string pointer in MyCookies
   do //Loop through all cookies
   {
      var CookieName=MyCookies.substring(StartAt, MyCookies.indexOf('=', StartAt)).replace(/^ /,''); //Get the next cookie name in the list, and strip off leading white space
      CookieNames.push(CookieName); //Remember the cookie name
      document.cookie=CookieName+"=;expires=Thu, 01-Jan-1970 00:00:01 GMT; path=/"; //Erase the cookie
      StartAt=MyCookies.indexOf(';', StartAt)+1; //Move the string pointer to the end of the current cookie
   } while(StartAt!=0)
   document.getElementById('CookieBox').value='Clearing: '+CookieNames.join("\nClearing: "); //Output the erased cookie names
}
</script>

Live Example: