The Cookie Technology

retrieve cookies with JavaScript

<HTML>
<HEAD><TITLE>JavaScript cookie example II<TITLE><HEAD>
<SCRIPT LANGUAGE = "JavaScript">
    var cookies = document.cookie;
    var cookie = "There was no cookie named username!";
    var searchfor = "username=";
    var start = 0;
    var end = 0;
    if ( cookies.length > 0 )
    {
        start = cookies.indexof ( searchfor );
        if ( start != -1 )
        {
            start += searchfor.length;
            end = cookies.indexof ( ";", start);
            if ( end = = -1 )
            {
                end = cookies.length;
            }
            cookie = " Found a cookie named username with a value of " + cookies.substring( start, end );
        }
    }
    alert ( cookie );
</SCRIPT>
<BODY><P>JavaScript example</P></BODY>
</HTML>
 

Notes