Advertisement
gunawantw

Cookies

Sep 6th, 2020
3,344
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function GetCookie (name) {
  2.     //alert("cookie yang mau diambil = " + name)
  3.    
  4.     var cookieFound = false;
  5.     var start = 0;
  6.     var end = 0;
  7.     var cookieString = document.cookie;
  8.     var i = 0;
  9.  
  10.     // SCAN THE COOKIE FOR name
  11.     while (i <= cookieString.length) {
  12.         start = i;
  13.         end = start + name.length;
  14.         if (cookieString.substring(start,end) == name) {
  15.             cookieFound = true;
  16.             break;
  17.         }
  18.         i++;
  19.     }
  20.  
  21.     // IS name FOUND?
  22.     if (cookieFound) {
  23.             start = end + 1;
  24.             end = document.cookie.indexOf(";",start);
  25.         if (end < start) end = document.cookie.length;
  26.         return document.cookie.substring(start,end);
  27.     }
  28.     return "";
  29.  
  30. }
  31.  
  32. function SetCookie (name, value) {
  33.     var argv = SetCookie.arguments
  34.     var argc = SetCookie.arguments.length
  35.     var expires = (argc > 2) ? argv[2] : null;
  36.         var path = (argc > 3) ? argv[3] : null;
  37.         var domain = (argc > 4) ? argv[4] : null;
  38.     var secure = (argc > 5) ? argv[5] : false;
  39.         document.cookie = name + "=" + value + ((expires == null) ? "" :  ("; expires=" + expires.toGMTString())) + ((path == null) ? "" : ("; path=" + path)) + ((domain == null) ? "" : ("; domain=" + domain)) + ((secure == true) ? "; secure" : "");
  40. }
  41.  
  42.  
  43. function DeleteCookie (name) {
  44.     //alert("will be delete cookie " + name + "with value = " + document.cookie)
  45.     var exp = new Date()
  46.     exp.setTime (exp.getTime() - 1)  // This cookie is history
  47.     var cval = GetCookie(name)
  48.     document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString()
  49. }
  50.  
  51.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement