Posted By

satie83 on 01/16/13


Tagged

javascript cookies


Versions (?)

JavaScript - Get Cookies


 / Published in: JavaScript
 

URL: http://www.electrictoolbox.com/javascript-get-all-cookies/

The following function loads all browser-cookies into an associative array with the cookie name as the index and the cookie value as the value

  1. function get_cookies_array()
  2. {
  3. var cookies = { };
  4.  
  5. if( document.cookie && document.cookie != '' ) {
  6. var split = document.cookie.split( ';' );
  7. for ( var i = 0; i < split.length; i++ ) {
  8. var name_value = split[i].split( "=" );
  9. name_value[0] = name_value[0].replace( /^ /, '' );
  10. cookies[decodeURIComponent( name_value[0] )] = decodeURIComponent( name_value[1] );
  11. }
  12. }
  13.  
  14. return cookies;
  15.  
  16. }

Report this snippet  

You need to login to post a comment.