TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
C# Corner
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Show All Cookies using JavaScript language
Omid Nasri
Apr 08
2016
Code
971
0
1
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
expand
/*
* return all cookies with array.
*/
function
get_cookies_array() {
var
cookies = { };
// if
document.cookie
not null or empty
if
(document.cookie && document.cookie !=
''
) {
var
split = document.cookie.split(
';'
);
for
(
var
i = 0; i < split.length; i++) {
var
name_value = split[i].split(
"="
);
name_value[0] = name_value[0].replace(/^ /,
''
);
cookies[decodeURIComponent(name_value[0])] = decodeURIComponent(name_value[1]);
}
}
return
cookies;
}
Example:
/*
* r
ead & show cookies name and value with loop from
get_cookies_array
() method.
*/
var
cookies = get_cookies_array();
for
(
var
name
in
cookies)
{ alert( name +
" : "
+ cookies[name] +
""
); }
JavaScript
Cookie