Knowledge Walls
Ammu
Hyderabad, Andhra Pradesh, India
Passcode:
Cookies in BOM of Javascript 1
1089 Views
Example 

What are Cookies?

Cookies are data, stored in small text files, on your computer.

When a web server has sent a web page to a browser, the connection is shut down, and the server forgets everything about the user.

Cookies were invented to solve the problem "how to remember information about the user":

  • When a user visits a web page, his/her name can be stored in a cookie.
  • Next time the user visits the page, the cookie "remembers" his/her name.

Cookies are saved in name-value pairs like:

Example
	<!DOCTYPE html>

	<head>

	    <title> Learning how to access elements from</title>

	    <script>

	        

	    </script>

	</head>

	<body>

	   <script>

	        function sgc() {

	//set cookie

	var now = new Date();

	now.setTime(now.getTime() + (60 * 1000));

	console.log(now);

	document.cookie = "name=value; expires="+now.toUTCString();

	            //document.cookie = "uid=12123234234; expires:Thu, 18 Jul 2019 07:30:00 UTC";

	//var utcc = new Date();

	//console.log(utcc.getDate());

	//document.cookie = "uname=John"; //settting multiple cookies

	            //console.log(document.cookie); //reading cookie,returns semicolon separated values.

	 

	//delete a cookie

	//document.cookie = "uid=";

	 

	//document.cookie = "uname=;  expires=Thu, 18 Jul 2018 10:20:00 UTC";

	//document.cookie = "uid=;  expires=Thu, 01 Jan 2018 00:00:00 UTC";

	console.log(document.cookie);

	        }

	    </script>

	    <button onclick="sgc()">Cookie</button>

	</body>

	</html>
Next Topics
Next lessons of current book.
Previous Topics
Previous lessons of current book.
Examples of Javascript 1
Examples of Javascript 1
Examples of Javascript 1
Examples of Javascript 1
Best Lessons of "Javascript 1"
Top lessons which are viewed more times.
Examples of Javascript 1
Examples of Javascript 1
Examples of Javascript 1
Examples of Javascript 1
Examples of Javascript 1
  Copyright © 2014 Knowledge walls, All rights reserved
KnowledgeWalls
keep your tutorials and learnings with KnowledgeWalls. Don't lose your learnings hereafter. Save and revise it whenever required.
Click here for more details