1
00:00:00,520 --> 00:00:01,240
Welcome back.

2
00:00:01,270 --> 00:00:07,030
So now that we have the ability to set cookies and don't forget that you need to be in the HRT protocol,

3
00:00:07,180 --> 00:00:10,270
not the final protocol, because you can't set cookies that way.

4
00:00:10,540 --> 00:00:14,290
We're going to also want to check to see which cookies exist.

5
00:00:14,500 --> 00:00:16,490
So that's the get cookie function.

6
00:00:16,750 --> 00:00:23,680
So when we retrieve back the cookie values, we can do that by getting the cookie document value.

7
00:00:23,980 --> 00:00:26,240
So could create a holder for that.

8
00:00:26,260 --> 00:00:31,120
And this can be called cookies using the document object.

9
00:00:32,180 --> 00:00:38,840
Getting the cookie value and we saw that last time, that if we write in a document cookie, we see

10
00:00:38,840 --> 00:00:40,250
a listing of all of the cookies.

11
00:00:40,430 --> 00:00:46,790
And if we have more than one type of cookie that we're setting in here and let me try that one more

12
00:00:46,790 --> 00:00:47,090
time.

13
00:00:48,680 --> 00:00:52,420
So now we've got two cookies and they're separated by the colon.

14
00:00:52,640 --> 00:01:00,860
So we want to do is take that cookie object and use JavaScript split to split all of the cookies that

15
00:01:00,860 --> 00:01:03,110
are currently contained within cookies.

16
00:01:03,380 --> 00:01:07,960
And we can console log out cookies whenever we do the get cookie.

17
00:01:08,120 --> 00:01:12,780
So you can see that when we do get cookie, we get both of the cookies that we set.

18
00:01:13,040 --> 00:01:19,600
So we want to do is we want to update we can also update that inner HTML of the output.

19
00:01:19,970 --> 00:01:26,080
So in case we don't find any cookies if we don't have any no cookies found.

20
00:01:26,120 --> 00:01:32,180
So this one just will say no cookies found and we'll update it as we loop through the cookies that we

21
00:01:32,180 --> 00:01:32,780
do find.

22
00:01:33,260 --> 00:01:34,640
And for each.

23
00:01:36,470 --> 00:01:43,960
And we have to look for a specific we can use item and index as well, so just as we used it before,

24
00:01:44,270 --> 00:01:49,610
so we want to make sure we want to check each one of the cookie names as we iterate through.

25
00:01:49,970 --> 00:01:51,440
So selecting the item.

26
00:01:51,770 --> 00:01:56,570
And we know that the item what we want to do is we want to trim the contents of item.

27
00:01:56,750 --> 00:02:00,980
So using JavaScript trim method, this will remove any of the whitespace.

28
00:02:02,730 --> 00:02:05,790
And maybe we can call this temp cookie.

29
00:02:07,940 --> 00:02:14,030
So we're taking each one of those and we want to split again, so on to create another array and this

30
00:02:14,030 --> 00:02:16,200
time splitting it by the equals sign.

31
00:02:16,430 --> 00:02:17,860
So this will break.

32
00:02:17,900 --> 00:02:19,850
So first we're splitting it by the colon.

33
00:02:20,070 --> 00:02:23,770
And you can see here that we've got a string for the cookies.

34
00:02:24,380 --> 00:02:25,790
We split it by colon.

35
00:02:25,790 --> 00:02:29,600
So that returns back an array with the two different cookies.

36
00:02:29,720 --> 00:02:31,790
And you see here we've got the white space.

37
00:02:32,090 --> 00:02:38,300
So that's why we're applying trim and that will trim any of the white space in front and after the string

38
00:02:38,300 --> 00:02:38,690
value.

39
00:02:38,710 --> 00:02:44,450
So that will return back just the string value and then we can use split to split it by the equals sign.

40
00:02:44,570 --> 00:02:48,780
And that will actually give us the cookie name where we can check.

41
00:02:49,400 --> 00:02:52,280
So if we cancel, log this out now.

42
00:02:52,430 --> 00:02:56,900
And I know we've got quite a bit of stuff here going on in the console, but this is just so that you

43
00:02:56,900 --> 00:03:02,120
can see when I do get cookies, we're returning back and we're splitting each one of those cookies.

44
00:03:02,270 --> 00:03:04,160
So we've got the name and the value.

45
00:03:04,340 --> 00:03:11,360
So as we loop through, we want to check to see if the name is equal to the name that we're looking

46
00:03:11,360 --> 00:03:11,560
for.

47
00:03:11,570 --> 00:03:19,370
So we're passing in a parameter here and checking to see if tempt cookie and because this is an array

48
00:03:19,370 --> 00:03:21,800
so in and get the first item in that index.

49
00:03:22,100 --> 00:03:28,070
So checking to see if temp cookie is equal to the name that was passed in as the parameter.

50
00:03:28,370 --> 00:03:33,480
And if it is, then this is where we can output the content from the cookie.

51
00:03:33,680 --> 00:03:41,030
So taking that cookie and we can say found and then we can set that as the cookie name if we wanted

52
00:03:41,030 --> 00:03:41,230
to.

53
00:03:41,330 --> 00:03:43,460
So temp cookie.

54
00:03:43,790 --> 00:03:47,150
And we want to also apply one more trim on that as well.

55
00:03:47,450 --> 00:03:55,190
So just in case we have some excess spacing around that item, we can trim that and then let's output

56
00:03:55,190 --> 00:03:59,450
the value and remember how we encoded it over here.

57
00:03:59,450 --> 00:04:00,040
The value.

58
00:04:00,290 --> 00:04:02,440
Well, in this case, we can decode.

59
00:04:02,450 --> 00:04:05,420
So instead of encode, this is going to be decoded.

60
00:04:05,840 --> 00:04:12,560
You are a component and we're taking the value from temp cookie one with the index value of ten, cookie

61
00:04:12,560 --> 00:04:13,820
one, as we saw.

62
00:04:13,850 --> 00:04:15,700
This is the value that's contained in there.

63
00:04:16,400 --> 00:04:19,940
So let's try that out and outputted it into our console.

64
00:04:19,950 --> 00:04:24,350
So again, refresh, make sure you're in the protocol and now we can get cookies.

65
00:04:24,530 --> 00:04:26,810
We know that we have a cookie by test name.

66
00:04:26,810 --> 00:04:30,830
So if we get the cookie, we see that the cookie is test value.

67
00:04:30,840 --> 00:04:33,770
So let's set this cookie as a test value.

68
00:04:33,770 --> 00:04:34,870
Five five five five.

69
00:04:35,100 --> 00:04:38,120
Now, when we do get we get that value being returned back.

70
00:04:38,310 --> 00:04:42,430
So even if we refresh and if we do get that, it's a cookie.

71
00:04:42,440 --> 00:04:47,600
So it's staying within the browser and we see that we're returning back the right value that we had

72
00:04:47,600 --> 00:04:48,800
set last time.

73
00:04:48,800 --> 00:04:51,620
And their current value right now is test value.

74
00:04:51,630 --> 00:04:52,520
So we can set it.

75
00:04:52,650 --> 00:04:56,920
And if we refresh and do get value, we see we're returning back to value.

76
00:04:57,290 --> 00:05:01,880
So that's how we can get cookies and I'll show you how we can quickly erase a cookie.

77
00:05:02,030 --> 00:05:05,810
So we saw when we were setting a cookie that we were getting the document cookie.

78
00:05:05,960 --> 00:05:07,040
We had the name.

79
00:05:07,040 --> 00:05:10,550
We're setting some information here and we can use the same thing.

80
00:05:10,560 --> 00:05:16,040
So for the erasing of the cookie, what we need to do is pass in that name.

81
00:05:16,040 --> 00:05:19,970
So that's the only thing that we really need and we can update its value.

82
00:05:19,980 --> 00:05:23,930
So it's not going to actually have a value because effectively we are raising it.

83
00:05:24,080 --> 00:05:25,160
So there's no value.

84
00:05:25,340 --> 00:05:28,670
The path is fine and we're going to set the expires.

85
00:05:28,820 --> 00:05:31,160
We're going to set it as a date and old date.

86
00:05:31,280 --> 00:05:34,730
So that will automatically expire that cookie value.

87
00:05:34,940 --> 00:05:36,620
So instead of setting a date.

88
00:05:37,830 --> 00:05:45,690
Setting it up as Thursday zero one, so any of the past dates is fine, 1970, and we're going to set

89
00:05:45,690 --> 00:05:46,770
it to the first.

90
00:05:47,810 --> 00:05:55,250
Value empty, and so what will happen here is that the cookie will be removed, so, Cookie, what that

91
00:05:55,250 --> 00:06:01,010
name is going to be removed and we can output some information into the output content.

92
00:06:01,640 --> 00:06:04,580
Let's try that in our browser.

93
00:06:05,060 --> 00:06:06,010
So refreshing.

94
00:06:06,020 --> 00:06:08,000
And again, remember that file protocol.

95
00:06:08,270 --> 00:06:10,370
So let's get the cookie.

96
00:06:10,380 --> 00:06:13,700
So we've got this cookie and now we want to delete the cookies.

97
00:06:13,700 --> 00:06:15,870
So the cookie name, we're going to delete it.

98
00:06:16,100 --> 00:06:21,940
So cookie name has been removed and when we do get cookies, no cookies found by that name.

99
00:06:22,250 --> 00:06:26,590
So we need to set it again and then we can get it and we get the cookie value.

100
00:06:26,870 --> 00:06:28,490
So that's how you can erase cookies.

101
00:06:28,670 --> 00:06:31,400
And lesson that we want to do is list out all the cookies.

102
00:06:31,580 --> 00:06:34,550
So this is going to be similar to what we just did with the cookie.

103
00:06:34,730 --> 00:06:39,980
And then we can complete the application where we can list out all the available cookies that have been

104
00:06:39,980 --> 00:06:40,430
set.

105
00:06:40,460 --> 00:06:42,500
So that's all still to come in the upcoming lesson.
