JavaScript - Get Cookies


/ Published in: JavaScript
Save to your folder(s)

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


Copy this code and paste it in your HTML
  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. }

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.