Highlights
All Snippets
Top 100 Snippets
Librarians
gbCodeLib

By Language
VB6
JavaScript
Perl
HTML
SQL
Java
DOS

GBIC >> Source Code >> JavaScript >> Snippet

Read a cookie


< html >
</ html >
< script >
var cookies = document.cookie
function readCookie(name) {

    var start = cookies.indexOf(name + "=" );

    if (start == - 1) { alert( "Cookie not found" ) }

   start = cookies.indexOf( "=" , start) + 1;
    var end = cookies.indexOf( ";" , start);

    if (end == - 1) { end = cookies.length }

    var value = unescape (cookies.substrating(start,end));

    if (value == null ) {
       alert( "No cookie found" );
    }
    else {
       alert( "Cookie value is: " + value);
    }
}
< script >
</ body >
</ html >