To read cookies in a JavaScript following is the JavaScript function which will help you to read the particular cookies with the name which you have supplied in the function
01 | <script> |
02 | |
03 | function readCookie(name) { |
04 | |
05 | var cookiename = name + "="; |
06 | |
07 | var ca = document.cookie.split(';'); |
08 | |
09 | for(var i=0;i < ca.length;i++) |
10 | { |
11 | |
12 | var c = ca[i]; |
13 | |
14 | while (c.charAt(0)==' ') c = c.substring(1,c.length); |
15 | |
16 | if (c.indexOf(cookiename) == 0) return c.substring(cookiename.length,c.length); |
17 | |
18 | } |
19 | |
20 | return null; |
21 | } |
22 | |
23 | document.write("n" + readCookie('site')); |
24 | |
25 | </script> |