Advertisement
Willcode4cash

Samyk/Evercookie

Sep 22nd, 2016
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
jQuery 1.29 KB | None | 0 0
  1. // https://github.com/samyk/evercookie
  2. // http://samy.pl/evercookie/
  3.  
  4.  <script type="text/javascript" src="evercookie.js"></script>
  5.  
  6.     <script>
  7.     var ec = new evercookie();
  8.    
  9.     // set a cookie "id" to "12345"
  10.     // usage: ec.set(key, value)
  11.     ec.set("id", "12345");
  12.    
  13.     // retrieve a cookie called "id" (simply)
  14.     ec.get("id", function(value) { alert("Cookie value is " + value) });
  15.  
  16.     // or use a more advanced callback function for getting our cookie
  17.     // the cookie value is the first param
  18.     // an object containing the different storage methods
  19.     // and returned cookie values is the second parameter
  20.     function getCookie(best_candidate, all_candidates)
  21.     {
  22.         alert("The retrieved cookie is: " + best_candidate + "\n" +
  23.             "You can see what each storage mechanism returned " +
  24.             "by looping through the all_candidates object.");
  25.  
  26.         for (var item in all_candidates)
  27.             document.write("Storage mechanism " + item +
  28.                 " returned: " + all_candidates[item] + "<br>");
  29.     }
  30.     ec.get("id", getCookie);
  31.    
  32.     // we look for "candidates" based off the number of "cookies" that
  33.     // come back matching since it's possible for mismatching cookies.
  34.     // the best candidate is most likely the correct one
  35.     </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement