/docs/cookies.js

http://gmaps-utility-library-flash.googlecode.com/ · JavaScript · 84 lines · 39 code · 4 blank · 41 comment · 7 complexity · 2eecae385f402eb9825fa5efc5c60dd3 MD5 · raw file

  1. ////////////////////////////////////////////////////////////////////////////////
  2. //
  3. // ADOBE SYSTEMS INCORPORATED
  4. // Copyright 2006-2007 Adobe Systems Incorporated
  5. // All Rights Reserved.
  6. //
  7. // NOTICE: Adobe permits you to use, modify, and distribute this file
  8. // in accordance with the terms of the license agreement accompanying it.
  9. //
  10. ////////////////////////////////////////////////////////////////////////////////
  11. /**
  12. * Read the JavaScript cookies tutorial at:
  13. * http://www.netspade.com/articles/javascript/cookies.xml
  14. */
  15. /**
  16. * Sets a Cookie with the given name and value.
  17. *
  18. * name Name of the cookie
  19. * value Value of the cookie
  20. * [expires] Expiration date of the cookie (default: end of current session)
  21. * [path] Path where the cookie is valid (default: path of calling document)
  22. * [domain] Domain where the cookie is valid
  23. * (default: domain of calling document)
  24. * [secure] Boolean value indicating if the cookie transmission requires a
  25. * secure transmission
  26. */
  27. function setCookie(name, value, expires, path, domain, secure)
  28. {
  29. document.cookie= name + "=" + escape(value) +
  30. ((expires) ? "; expires=" + expires.toGMTString() : "") +
  31. ((path) ? "; path=" + path : "") +
  32. ((domain) ? "; domain=" + domain : "") +
  33. ((secure) ? "; secure" : "");
  34. }
  35. /**
  36. * Gets the value of the specified cookie.
  37. *
  38. * name Name of the desired cookie.
  39. *
  40. * Returns a string containing value of specified cookie,
  41. * or null if cookie does not exist.
  42. */
  43. function getCookie(name)
  44. {
  45. var dc = document.cookie;
  46. var prefix = name + "=";
  47. var begin = dc.indexOf("; " + prefix);
  48. if (begin == -1)
  49. {
  50. begin = dc.indexOf(prefix);
  51. if (begin != 0) return null;
  52. }
  53. else
  54. {
  55. begin += 2;
  56. }
  57. var end = document.cookie.indexOf(";", begin);
  58. if (end == -1)
  59. {
  60. end = dc.length;
  61. }
  62. return unescape(dc.substring(begin + prefix.length, end));
  63. }
  64. /**
  65. * Deletes the specified cookie.
  66. *
  67. * name name of the cookie
  68. * [path] path of the cookie (must be same as path used to create cookie)
  69. * [domain] domain of the cookie (must be same as domain used to create cookie)
  70. */
  71. function deleteCookie(name, path, domain)
  72. {
  73. if (getCookie(name))
  74. {
  75. document.cookie = name + "=" +
  76. ((path) ? "; path=" + path : "") +
  77. ((domain) ? "; domain=" + domain : "") +
  78. "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  79. }
  80. }