Asked by Michael Munger
at 2024-08-07 12:13:33
Point:500 Replies:7 POST_ID:828708USER_ID:11410
Topic:
JavaScript;;jQuery
I have a wordpress plugin that does suggestions and reminders that I am writing. The object is: when a person scrolls down the page x pixels, it says: "You may also find this other article useful" (A common function).
What I want to do is this: when a person clicks "no thanks", I want to save a cookie on their machine so that we will never again prompt them with this suggestions for that page for another year (or until they empty their cookies).
Since storing an entire URL as the cookie name has proven to be a bad strategy, I am storing it as an MD5 hash of the full URL.
Creating the cookie works.
However, reading the cookie doesn't.
When I read the cookie, it will either return true (as a string) if they have been to that page before or undefined if the cookie for that page doesn't exist.
My if statements don't work.
What did I do wrong here?
You can see from this image, the MD5 hash for this page is 95f3f49c66555d97b44738bda2e805d7. You can also see that the browser thinks that there is no cookie with this hash in the browser:
What I want to do is this: when a person clicks "no thanks", I want to save a cookie on their machine so that we will never again prompt them with this suggestions for that page for another year (or until they empty their cookies).
Since storing an entire URL as the cookie name has proven to be a bad strategy, I am storing it as an MD5 hash of the full URL.
Creating the cookie works.
However, reading the cookie doesn't.
When I read the cookie, it will either return true (as a string) if they have been to that page before or undefined if the cookie for that page doesn't exist.
My if statements don't work.
What did I do wrong here?
You can see from this image, the MD5 hash for this page is 95f3f49c66555d97b44738bda2e805d7. You can also see that the browser thinks that there is no cookie with this hash in the browser:
But the cookie is really there:
Here's the code in question:
Libraries in use:
date.js: https://github.com/carhartl/jquery-cookie
md5.js: https://code.google.com/p/crypto-js/

