Ottenere tutti i cookie del browser con Javascript

La seguente funzione carica tutti i cookie del browser in un array associativo con il nome del cookie come indice e il valore del cookie come valore.

 
function get_cookies_array()
{
    var cookies = { };
 
    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;
 
}
 

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>