Incognition

Untitled

Jan 23rd, 2016
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function createCookie( name, value, days )
  2. {
  3.     var expires;
  4.  
  5.     if ( days )
  6.     {
  7.         var date = new Date();
  8.         date.setTime( date.getTime() + ( days * 24 * 60 * 60 * 1000 ) );
  9.         expires = "; expires=" + date.toGMTString();
  10.     }
  11.     else
  12.     {
  13.         expires = "";
  14.     }
  15.     document.cookie = encodeURIComponent(name) + "=" + encodeURIComponent(value) + expires + "; path=/";
  16. }
  17.  
  18. function readCookie( name )
  19. {
  20.     var nameEQ = encodeURIComponent(name) + "=";
  21.     var ca = document.cookie.split( ';' );
  22.     for (var i = 0; i < ca.length; i++)
  23.     {
  24.         var c = ca[ i ];
  25.         while ( c.charAt( 0 ) === ' ' )
  26.             c = c.substring(1, c.length);
  27.             if ( c.indexOf( nameEQ ) === 0 )
  28.                 return decodeURIComponent( c.substring( nameEQ.length, c.length ) );
  29.     }
  30.  
  31.     return null;
  32. }
  33.  
  34. function eraseCookie( name )
  35. {
  36.     createCookie( name, "", -1 );
  37. }
Advertisement
Add Comment
Please, Sign In to add comment