Answer the question
In order to leave comments, you need to log in
How to check if evercookie exists, if not, create it?
What is the point, I want to check if evercook exists, if it does not exist, I need to create it.
I use the library https://github.com/samyk/evercookie
var ec = new evercookie();
// set a cookie "id" to "12345"
// usage: ec.set(key, value)
// ec.set("id", "123456");
// retrieve a cookie called "id" (simply)
// ec.get("id", function(value) { console.log(value); });
// or use a more advanced callback function for getting our cookie
// the cookie value is the first param
// an object containing the different storage methods
// and returned cookie values is the second parameter
function getCookie(value)
{
if(typeof value !== 'undefined' && value !== null) {
return false;
}
}
if(ec.get("id", getCookie)) {
console.log(1);
} else {
console.log(2);
}
// we look for "candidates" based off the number of "cookies" that
// come back matching since it's possible for mismatching cookies.
// the best candidate is most likely the correct one
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question