Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / NewStats: 3,205,413 members, 7,992,368 topics. Date: Sunday, 03 November 2024 at 01:47 AM |
Nairaland Forum / Science/Technology / Webmasters / How To Store Data With javascript / Javascript Cookie Workshop (18969 Views)
(New) Get Airtel 1gb data with 100 naira only.( / Hlp With Javascript Snippet To Validate A User's Cell Phone Number Input / Trouble With Javascript Code (2) (3) (4)
How To Store Data With javascript / Javascript Cookie Workshop by Nobody: 2:29pm On Jan 06, 2009 |
Please visit the new cookie thread - https://www.nairaland.com/2430372/cookie-programming-javascript 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 Nobody: 3:03pm On Jan 06, 2009 |
Demo 1: http://.net/demos/cookies/change.htm - storing personal info Demo 2: http://.net/demos/cookies/jc2.htm - javascript counter You can download those demos on http://.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://.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 Nobody: 3:06pm On Jan 06, 2009 |
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
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 Nobody: 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. 1 Like |
Re: How To Store Data With javascript / Javascript Cookie Workshop by blueyedgeek(m): 8:32pm On Nov 29, 2014 |
Cool tutorial |
Re: How To Store Data With javascript / Javascript Cookie Workshop by Nobody: 9:46pm On Nov 29, 2014 |
You had to dig up this archive eh? Thanks for the compliment. 1 Like |
(1) (Reply)
Top 10 Blogs That Accept Guest Posts In Nigeria / Why Do Nigerians Hate Commenting On Tech Blogs? / Your Paypal Account Is Limit ? Want To Cashout Or Lifted Limit ?
(Go Up)
Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health religion celebs tv-movies music-radio literature webmasters programming techmarket Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10) Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 35 |