Jump to content
Sign in to follow this  
adrian.m123

Deleting a cookie with value NULL

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?

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...