D
D
Dmitry Tarasov2018-09-30 14:56:18
JavaScript
Dmitry Tarasov, 2018-09-30 14:56:18

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

if(ec.get("id", getCookie)) {
console.log(1);
} else {
console.log(2);
}
this code always outputs console.log(2), as if it doesn't care about return in the getCookie function, maybe I'm doing something wrong ?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrew, 2018-09-30
@fast-je

if(ec.get("id", getCookie(value))) {
          console.log(1);
      } else {
          console.log(2);
      }

So?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question