Wednesday 17 June 2015

tutorial on cookie

Hi all,

Have you ever wondered how does information of user session are stored in client side? how does website checks which user is currently logged in or is not logged in? What is the favorite food for kids?

Answer to all of the above is Cookie!

So in this post we are going to learn about cookie in javascript. Cookies are data, stored in small text files, on your computer. It's use is to remember user data.

cookies are stored as name, value pair username = zeel
to create a new cookie
document.cookie = "cookiename = cookievalue; expires = utc time;path=/;"


by default cookie is deleted when browser is closed otherwise it will be expired after the time specify.
if you set the path of the cookie then that is not available to parent directory but it's available to subdirectories.

you can access cookie in javascript using document object via
var cookie = document.cookie; and then search the cookie name after iternating through each of the cookie after spliting it by ;.


you can found more details information on http://www.w3schools.com/js/js_cookies.asp

No comments:

Post a Comment