Jump to content

Deleting a cookie with value NULL


adrian.m123

Recommended Posts

I'm trying to erase completely a cookie that is set if a particular URL parameter is present.I've tried: function delete_cookie( name ) {document.cookie = name + '=; path=/; expires=Thu, 01 Jan 1970 00:00:01 GMT;';}

 

And it sets the cookie value to null but the cookie itself or at least the name of the cookie stays in the browser so that when the same URL is opened again, it will not update the cookie value from null to XXX nor is a second cookie with the URL value created.For the new cookie to be setup again I have to right-click on the cookie name (in Chrome) and choose delete. This way the cookie name and its value null are truly erased otherwise it stays with null value.How can I completely erase the cookie file and not just set it to null with javascript?I should mention that I also have the following function to grab the cookie from the URL parameter and to keep it from the first page until the final page (where it should be deleted after the cookie value is added as the value of an external URL parameter to an external within the final page). The second page will turn the original link into a session where the URL parameter is no longer visible.The link would be: http://xxxx.test.yyyy/index.html?myparameter[zzzzzz]=ddddd Here is the code for it:function URLparam(name) {return unescape((RegExp(name + '(?:[d+])?=' + '(.+?)(&|$)').exec(location.search)||[,null])[1]);}$(document).ready(function () {if (URLparam("MyParameter") !== null && !get_cookie ("MyCookie")) {set_cookie ("MyCookie", URLparam("MyParameter"));}

 

Any ideas?

Link to comment
Share on other sites

Setting "expires" to a date prior to the current date is what should actually delete the cookie, But you probably should use the exact same "path" value as you did when setting the cookie; If no path was set then you shouldn't add "path" to the deleting function. It's probable that a cookies with different paths are considered different cookies.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...