����� 2
�� 10: ����� cookies �������.
�� ���� ��- cookie ��� ����� ���� ����� ���� ���, ���� ������ �� �- cookie ��� ����� (�� ���� �� 4KB). ����, ������� ����� �� ��� �� �����, ���� ����� ������ ���. ���� ����� ���� ����� ��:
var the_cookie = "username:thau/age:older than the hills/phone:411";
document.cookie="my_happy_cookie=" + escape(the_cookie);
��� ���� ����� ������ �� ��� ������ ��� �������� ����� ����������� �� ��� ������ ��� �� ������� �����. ������ �����������, �� ������ ��������� ��� � �� ������ ����� �� ��� �����. ����:
var the_cookie = "username=thau&age=older than the hills&phone=411";
document.cookie="my_happy_cookie=" + escape(the_cookie);
������ �������� ������ ����� �� �� �����, ���� ���� ������ ���� �� ��� ����� ����� �� �- cookie ����� ����� ����.
��� ������ ������ ����, ���� ��� ��� ���� �- cookie, ����, ����� ����� ����� ���� �- cookie ��� ���� �����. ��� ���� ������ ������� ����������� �� ��� ����� �� �����. ��� ����, ����, ����� �� �- cookie ��� ����� ����� �� �����:
my_happy_cookie=username:thau/age:older than the hills/phone:411
���� ����� �� ����� ����� ���������� ��:
function readTheCookie(the_info)
{
// load the cookie into a variable and unescape it
var the_cookie = document.cookie;
var the_cookie = unescape(the_cookie);
// separate the values from the cookie name
var broken_cookie = the_cookie.split("=");
var the_values = broken_cookie[1];
// break each name:value pair into an array
var separated_values = the_values.split("/");
// loop through the list of name:values and load
// up the associate array
var property_value = "";
for (loop = 0; loop < separated_values.length; loop++)
{
property_value = separated_values[loop];
var broken_info = property_value.split(":");
var the_property = broken_info[0];
var the_value = broken_info[1];
the_info[the_property] = the_value;
}
}
�� �������� ��� ����� ����� ���� �- JavaScript ���, ����� ����� �� ��:
var cookie_information = new Array();
readTheCookie(cookie_information);
������ ���, �"� ������: ["cookie_information["username"], cookie_information["age �- ["cookie_information["phone ���� ���� �� ����� ������.
�� ���� ���� ����, ���� ����� �� ����� ��� ����� �����, ����� �����, ��� �� ��� ���. ��� ����� �� ���� ���� ��� ����:
var the_cookie = document.cookie;
�� ���� ���. ���� ������ �� �- cookie ���� �����.
var the_cookie = unescape(the_cookie);
var broken_cookie = the_cookie.split("=");
var the_values = broken_cookie[1];
��� ����� ��� ������ �� ���� �� ������ the_values �����: " username:thau/age:older than the hills/phone:411".
var separated_values = the_values.split("/");
���� �� ����� ���� ��� seperated_values ��� ����� �������:
separated_values[0] = "username:thau", separated_values[1] = "age:older than the hills", separated_values[2] = "phone:411".
for (loop = 0; loop < separated_values.length; loop++)
���� �� �����, ����� ����� ������ �� ����� ������� �����.
property_value = separated_values[loop];
��� ��� ������ �� ������ name:value (���:��), ���� ���� ������ ���: username:thau.
var broken_info = property_value.split(":");
����� �� ��� ������� �� ������ ���� ���� ����� ���: broken_info, ����: broken_info[0] = "username", broken_info[1] = "thau".
var the_property = broken_info[0];
����� ������ �������, the_property ����: "username".
var the_value = broken_info[1];
����� ������ �� ������, the_value ����: "thau".
the_info[the_property] = the_value;
��� �������, ��� ����� �� ������ ������� ������� �������. the_info["username"] ���� �� ���� "thau". �� ����� ���� �� �� ������ ��- cookie, ���� ���� ����� �� ����� ����:the_name = the_info["username"];.
��� ���� ��� ���� ...
��, ��� ��� ����� ���� ������, ����� ��� ������ �� the_info. ���� ������ ���� ��:
the_info["username"] = "thau"
the_info["age"] = "old as the hills"
the_info["phone"] = 411
�� ���� ���� ��� ������, ��� �� ���� ��� ��� ����� ������ �� ��� ����� ���� �� �- cookies �� ����� ���. ���� ����� ���� ����� ���, ��� ���� ��� ���� ���� ����� ��, ��� ���� ��.
���, ���� ������ ����� �� ��� ����, ��� ���� ������ ����� �� �� cookies ������.
���� ������ ���
��� ��� «--
|