How to write Cookies in Javascript
Hello Friends,
In my web browser I wanted to set cookies which will help me in showing the Visited sites in the site address name,day,date and time, please help me giving some idea about the same.
I know this is possible but I stuck where should I starts from.
Any help would be Appreciated :notworthy
Re: How to write Cookies in Javascript
Cookies in JavaScript are accessed using the cookie property of the document object. In simple terms, we create a cookie like this:
Code:
document.cookie = "name=value; expires=date; path=path;
domain=domain; secure";
..and retrieve all our previously set cookies like this:
Code:
var x = document.cookie;
Let's look more closely at how to set and retrieve cookies.To set a cookie, we set the document.cookie property to a string containing the properties of the cookie that we want to create:
Quote:
document.cookie = "name=value; expires=date; path=path;
domain=domain; secure";
Re: How to write Cookies in Javascript
It would be more difficult to explain all about the Cookie but i can tell you where we can store the Cookie,Physically, cookies are stored in a location known only to the browser, although for the main browser platforms, these locations are well-known. Logically, a cookie belongs to a domain and a path. When the JavaScript set cookies process is invoked, the script either presents the browser with a domain, or a blank value. If no domain is given it is assumed to be the domain of the page
Re: How to write Cookies in Javascript
First, we create a function that stores the name of the visitor in a cookie variable:
Code:
function setCookie(c_name,value,expiredays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie=c_name+ "=" +escape(value)+
((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}
The parameters of the function above hold the name of the cookie, the value of the cookie, and the number of days until the cookie expires.