piers_morgan
09-18-2003, 06:51 AM
Hoping someone can help. Have the following script, which remembers your visitor's name if they've been to your site. The only thing is, it doesn't work in terms of remembering their name and I'm not sure where I am going wrong. Have set the expirey date to the future and the past but this doesn't make much of a difference. Any help appreciated. Alternatively, if anyone can point me in the right direction of a script that works...
Piers
</script>
<font color="#FF8000"><b><font color="#FF8000"><b><i><font color="#000066">
<script language="JavaScript">
function getname(){
//this is the name of the function
var thiscookie=document.cookie;
//this retrieves the cookie
var location=thiscookie.indexOf("surfername=");
//this is the location of where the information starts
var endlocation=thiscookie.indexOf(":");
//this is the location of the end of the information
if (location != -1){
//this checks to see if the cookie exists
var begin=location+11;
//this gets the location of the beginning of the surfer's name
var yourname=thiscookie.substring(begin, endlocation);
//this grabs the value from the cookie
yourname = unescape(yourname);
//this unencodes the surfer's name
return yourname;
//this returns the surfer's name
}
else{
var yourname = prompt("Welcome, please enter in your name.",''); //this asks for the name
document.cookie = "surfername=" + escape(yourname)+":" + "expires=Fri Dec 10 11:00:00 PST 2003";
//sets the cookie with a name=value pair of surfername=value
//you may modify the expiration date by changing the expires=
}
return yourname; //this returns the surfer's name
}
document.write("Welcome to .Net, " + getname() + "!");
</script>
:confused:
Piers
</script>
<font color="#FF8000"><b><font color="#FF8000"><b><i><font color="#000066">
<script language="JavaScript">
function getname(){
//this is the name of the function
var thiscookie=document.cookie;
//this retrieves the cookie
var location=thiscookie.indexOf("surfername=");
//this is the location of where the information starts
var endlocation=thiscookie.indexOf(":");
//this is the location of the end of the information
if (location != -1){
//this checks to see if the cookie exists
var begin=location+11;
//this gets the location of the beginning of the surfer's name
var yourname=thiscookie.substring(begin, endlocation);
//this grabs the value from the cookie
yourname = unescape(yourname);
//this unencodes the surfer's name
return yourname;
//this returns the surfer's name
}
else{
var yourname = prompt("Welcome, please enter in your name.",''); //this asks for the name
document.cookie = "surfername=" + escape(yourname)+":" + "expires=Fri Dec 10 11:00:00 PST 2003";
//sets the cookie with a name=value pair of surfername=value
//you may modify the expiration date by changing the expires=
}
return yourname; //this returns the surfer's name
}
document.write("Welcome to .Net, " + getname() + "!");
</script>
:confused: