Nairaland ForumWelcome, Guest: Join Nairaland / Login / Trending / Recent / NewStats: 1063340 members, 1236959 topics. Date: Saturday, 25 May 2013 at 08:00 AM |
Nairaland Forum / Science/Technology / Webmasters / How To Store Data With javascript / Javascript Cookie Workshop (13582 Views)
Xml Potential Uncovered. Parsing Xml With Javascript In D Dynamic Way. / [SOLVED!] Cookie Not Set Using Setcookie(). Help! / Trouble With Javascript Code (1) (2) (3) (4)
| How To Store Data With javascript / Javascript Cookie Workshop by *dhtml(m): 2:29pm On Jan 06, 2009 |
Today, we are going to learn how to save website information into the client system. This is the trick also to remembering the last page a user visited on your website after the client closes the browser, some use it to support sessions by saving username, i am talking of that feature we keep seeing on login pages that says - remember me on this computer, all these and lots ore can be done with cookies. Since this is a workshop, i will talk about using cookies directly and how to use classes to access cookies. Before we go into coding let me paste a few intros here
|
| Re: How To Store Data With javascript / Javascript Cookie Workshop by *dhtml(m): 3:03pm On Jan 06, 2009 |
Demo 1: http://dhtmlextreme.net/demos/cookies/change.htm - storing personal info Demo 2: http://dhtmlextreme.net/demos/cookies/jc2.htm - javascript counter You can download those demos on http://dhtmlextreme.net/?net=dl I will not explain those source codes - those are complete samples - but rather i want to give a short training on the basics of cookies. At this point i am tempted to create a cookie class for easy learning, then i will now break down the class cookie.class.js
The class contains 3 methods/functions: set - to create a cookie get - to retrieve a cookie erase- to clear out a cookie I am going to implement that class now cookie.test.html
I will leave it for you to compile the 2 - demo will be http://dhtmlextreme.net/demos/cookies/cookie.test.html And for this demo, all you need do is launch it, type in a value, click on save. You can close the browser, then reopen the page in the same browser on the same system, then click on the load button, u should have your contents back. Next lesson: we are going to break the code code into bits and pieces. |
| Re: How To Store Data With javascript / Javascript Cookie Workshop by *dhtml(m): 3:06pm On Jan 06, 2009 |
Demo 1: http://dhtmlextreme.net/demos/cookies/change.htm - storing personal info Demo 2: http://dhtmlextreme.net/demos/cookies/jc2.htm - javascript counter You can download those demos on http://dhtmlextreme.net/?net=dl I will not explain those source codes - those are complete samples - but rather i want to give a short training on the basics of cookies. At this point i am tempted to create a cookie class for easy learning, then i will now break down the class cookie.class.js
The class contains 3 methods/functions: set - to create a cookie get - to retrieve a cookie erase- to clear out a cookie I am going to implement that class now cookie.test.html
I will leave it for you to compile the 2 - demo will be http://dhtmlextreme.net/demos/cookies/cookie.test.html And for this demo, all you need do is launch it, type in a value, click on save. You can close the browser, then reopen the page in the same browser on the same system, then click on the load button, u should have your contents back. Next lesson: we are going to break the code code into bits and pieces. |
| Re: How To Store Data With javascript / Javascript Cookie Workshop by *dhtml(m): 3:19pm On Jan 06, 2009 |
This is How to Create a Cookie document.cookie = cname + "=" + escape(cvalue) + "; expires=Mon, 31 Dec 2099 23:59:59 UTC;path=/;"; where cname is the name of the cookie and cvalue is the information the cookie contains. The date specified there is the expiry date of the cookie when the browser will automatically delete the cookie. The path refers to what domain within your site can access it. For learners, just use / if you are online, but if you are running this without a web server as c:\documents and settings\desktop\cookie.test.html just use / instead. This is How To Get A Cookie
All the cookies of a web page are attached to the document that created them - so you need to run a loop through them. Getting cookies is easier than creating them - just understand how the structure works in case you cannot read jscript arrays. *************************** That Ends This Workshop ***********************************************8 Questions can now follow as usual if any. |
(0) (Reply)
Learn How To Get Free 60 Mb On Ur Etisalat Sim / Your Top 5 Nigerian Everyday Websites / Meet The World's Fastest Internet Millionaire (it Took Him Just 5 Months)
(Go Up)
Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health Links: (0) (1) (2) (3) (4) (5) (6) (7) (8) (9) Nairaland - Copyright © 2005 - 2013 Oluwaseun Osewa. All rights reserved. See Privacy Policy & Nairalist. 54.234.180.187 |