Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6586531
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T16:48:07+00:00 2026-05-25T16:48:07+00:00

I need to delete clientside cookies with the same name but with different paths.

  • 0

I need to delete clientside cookies with the same name but with different paths. What is the best way to do this in javascript.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T16:48:08+00:00Added an answer on May 25, 2026 at 4:48 pm

    Just specify the same path of the cookie you want to remove, giving it a past expiration.

    document.cookie = 'name=value1; path=/';
    document.cookie = 'name=value2; path=/path/';
    
    alert(document.cookie); // name=value1; name=value2
    
    
    document.cookie = 'name=; path=/path/; expires=' + new Date(0).toUTCString();
    
    alert(document.cookie); // name=value1
    

    Changing it to expire the cookie with a path of / will still only expire one of the cookies — the path given has to match the path set:

    document.cookie = 'name=; path=/; expires=' + new Date(0).toUTCString();
    
    alert(document.cookie); // name=value2
    

    To remove both, you’ll have to expire each with their path:

    document.cookie = 'name=; path=/; expires=' + new Date(0).toUTCString();
    document.cookie = 'name=; path=/path/; expires=' + new Date(0).toUTCString();
    
    alert(document.cookie); // {blank}
    

    Now, these examples assume you’re browsing /path/ or a sub-directory of it.


    [edit]

    To remove in bulk, try something like this:

    function expireAllCookies(name, paths) {
        var expires = new Date(0).toUTCString();
    
        // expire null-path cookies as well
        document.cookie = name + '=; expires=' + expires;
    
        for (var i = 0, l = paths.length; i < l; i++) {
            document.cookie = name + '=; path=' + paths[i] + '; expires=' + expires;
        }
    }
    
    expireAllCookies('name', ['/', '/path/']);
    

    Demo: http://jsfiddle.net/M2dZ3/

    You can also fake path lookups by splitting and iterating window.location.pathname:

    function expireActiveCookies(name) {
        var pathname = location.pathname.replace(/\/$/, ''),
            segments = pathname.split('/'),
            paths = [];
    
        for (var i = 0, l = segments.length, path; i < l; i++) {
            path = segments.slice(0, i + 1).join('/');
    
            paths.push(path);       // as file
            paths.push(path + '/'); // as directory
        }
    
        expireAllCookies(name, paths);
    }
    

    Demo: http://jsfiddle.net/M2dZ3/2/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to delete the latest browser history entry for this reason , but
I need to delete a file. Occasionally, the file may be locked, in this
I need to delete an exact line from a text file but I cannot
I need to delete from a table rows that have the same value on
I need to delete only the first appear of a record. This have a
I need to delete a temporary file from my C++ windows application (developed in
I need to delete a regsitry key. It has a deny ACL on Set
I need to delete some Unicode symbols from the string 'بِسْمِ اللَّهِ الرَّحْمَٰنِ الرَّحِيمِ'
I need to delete my input file securely once I have finished with it,
I need to delete files of a certain type (.zip files, say) from a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.