|
|
JavaScripts :: Cookies :: Redirection Cookie
This javascript will read any existing cookies on the current visitor's computer that have been set by your web site. It assumes you have already set cookies and you know the name of them. You can then query the script using the cookie name and print out the value. See this page for information on how to set cookies using javascript.
The following example queries the script for a cookie named "mycookie" and a second cookie named "yourcookie". If the cookies are found (have been set) they are then written to the web page using the document.write() method. However with some modifications you could have the data printed to form fields.
The Script
<script>
<!--
/* Copyright http://www.perlscriptsjavascripts.com
Free and commercial Perl and JavaScripts */
function printCookies(w){
cName = "";
pCOOKIES = new Array();
pCOOKIES = document.cookie.split('; ');
for(bb = 0; bb < pCOOKIES.length; bb++){
NmeVal = new Array();
NmeVal = pCOOKIES[bb].split('=');
if(NmeVal[0] == w){
cName = NmeVal[1];
}
}
return cName;
}
first = printCookies("mycookie");
second = printCookies("yourcookie");
document.write("<b>" + first + "</b><p>");
document.write(second);
// -->
</script>
|
|
|