Setting a Cookie in Javascript


/ Published in: JavaScript
Save to your folder(s)



Copy this code and paste it in your HTML
  1. function setCookie() {
  2. var name = prompt('Name of the cookie');
  3. var value = prompt('Value of the cookie');
  4. var expires = prompt('Cookie expiration date');
  5. var path = prompt('Cookie path scope');
  6. var domain = prompt('Domain path scope');
  7. var secure = confirm('secure');
  8. var curCookie = name + "=" + escape(value) +
  9. ((expires) ? "; expires=" + expires.toGMTString() : "") +
  10. ((path) ? "; path=" + path : "") +
  11. ((domain) ? "; domain=" + domain : "") +
  12. ((secure) ? "; secure" : "");
  13. document.cookie = curCookie;
  14. return curCookie;
  15. }

URL: http://www.arachna.com/edu/tutorials/mini/cookies/javascript.html

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.