Pak Jiddat - Innovative Software Services

Read: In the name of thy Lord Who createth, Createth man from a clot. Read: And thy Lord is the Most Bounteous, Who teacheth by the pen, Teacheth man that which he knew not. Nay, but verily man is rebellious That he thinketh himself independent!. Lo! unto thy Lord is the return. (Sura Alalaq 96:8)

Using cookies in Javascript

Created On: 16 Dec, 2017: 22:33:14 - Tags : javascript

Url: http://www.w3schools.com/js/js_cookies.asp

Cookies allow websites to store information on the user browsers. They are usually used to store website session related information. To set a cookie using JavaScript we can use document.cookie="cookie_name=cookie_value". Multiple cookie values should be separated by ';'.

The cookie string can contain the date of expiry of the cookie as well as the url path for which the cookie is valid. By default the cookie belongs to the current page. An example of setting a cookie using JavaScript: document.cookie = "username=John Doe; expires=Thu, 18 Dec 2013 12:00:00 UTC; path=/";

To fetch the value of a cookie we can assign the document.cookie property to a variable. For example: var cookies = document.cookie. We will then have to parse the values of the individual cookies

To delete a cookie, we need to set the value of the cookie to an empty string and the value of the expires property to the required value

Cookies in JavaScript: Ultimate Guide is a useful guide that describes the relevance of cookies and how to create, access and remove cookies in JavaScript.


Related Articles

  1. Adding event listeners using JavaScript
  2. Using Prefetch, Preload and Preconnect for speeding page load times
  3. Get current unix timestamp using Javascript
  4. Fetching html elements using CSS selectors with Javascript
  5. Fetching html elements using CSS class names
  6. Fetching parent node element of a HTML node
  7. Adding option to html selectbox using Javascript
  8. Changing CSS styles using Javascript
  9. Allowing Cross Origin Requests using htaccess
  10. NodeJs permission denied error
  11. Customizing Redmine layout
  12. Passing parameters to Jquery event handler function
  13. W3C.Data
  14. Making cross domain Ajax calls using JSONP
  15. Use of Preflight request in HTTP Cross Origin Resourse Sharing (CORS)
  16. Javascript JSON guide
  17. Convert javascript object to json string
  18. Javascript date object
  19. Get the time using JavaScript
  20. Using keydown event handler for detecting enter key press
  21. Get co-ordinates of element relative to document using Jquery
  22. Using clearTimeout and onmouseenter, onemouseleave events
  23. Replacing a string using Javascript replace function
  24. Base64 Encoding of utf-8 encoded string using Javascript
  25. Setting CSS styles using JQuery
  26. Replacing html element using replaceWith jquery function
  27. Iterate throught Javascript object properties
  28. Select contents on text field