Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to create deleteCookie() function in JavaScript

    • 0
    • 1
    • 1
    • 1
    • 0
    • 0
    • 0
    • 0
    • 383
    Comment on it

    With the help of javascript, I have created deleteCookie() function. In the code given below, I have stored all the values in a single cookie and then used deleteCookie() function for deleting the cookie. When the cookie session expires, previous cookie will be overwritten and the new cookie (new one) will instantly be expired.

     <script type="text/javascript">
     var expired = new Date(today.getTime() - 24 * 3600 * 1000); // less 24 hours
    
      function deleteCookie(name)
      {
        document.cookie=name + "=null; path=/; expires=" + expired.toGMTString();
      }
     </script>
    

    Calls this function to deletes the cookies:-

    <script type="text/javascript">
       function clearCookies()
      {
        deleteCookie("field1");
        deleteCookie("field2");
        deleteCookie("field3"); 
        deleteCookie("field4");
        alert('Your cookies have been deleted!');
      }
    </script>
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: