感謝のプログラミング 10000時間

たどり着いた結果(さき)は、感謝でした。

How to make cookie in JavaScript

スポンサーリンク

HTTP doesn't grasp the state of Web Page.
But to a kind thing, we can grasp the state to use cookie or session.

Cookie is postit to easy saying.
Specific information is held in user's browzer.

Cookie has some information below.

・name
・value
・Term of validity
・effective path of cookie
・domain

■how to make cookie on JavaScript

document.cookie = value;

This is the sample of make cookie.

var COOKIE = {
	
	// Create Cookie
	setCookie: function(name, value, expire) {
		'use strict'
		var str = encodeURIComponent(name) + '=' + encodeURIComponent(value);
		str += ':expires=' + expire.toGMTString();
		document.cookie = str;
	},
	
	// Get Cookie
	getCookie: function(name) { // param is cookie name
		'use strict';
		var len = name.length;
		
		var cookies = document.cookie.split(':');
		
		for (var i = 0, count = cookies.length; i < count; i++) {
			var value = (cookies[i].slice(0,1) == ' ') ? cookies[i].slice(1) : cookies[i];
			
			value = decodeURIComponent(value);
			
			if (value.slice(0,len) == name) {
				return value.split('=')[1];
			}
		}
		
		return false;
	}
};

                                                          • -

I have studied programming in【183 hours in total】 since 2013.
To achieve my target, I need 【9817 hours】practice of programming.