Welcome to WebmasterWorld Guest from 174.129.127.214

Forum Moderators: open

Message Too Old, No Replies

JS userName script query

need link to reload page and clear cookie

   
5:45 am on Mar 16, 2003 (gmt 0)

10+ Year Member



Hello all,

I am building a kids (no profit) site and though I am presently learning JS in a tech college here in ozland, I am not able to write or modify a cookie username script which would be a real treat for my site surfers.

I am looking for something like the macomedia username which stores the details, but also writesIn "if this is not +user+ click here. I assume this reloads the page and clears the cookie at the same time. This is precisely where I am having the problem. I have a username script without that extra bit. Can anyone suggest where I can find this script?

thanks again
antipodes

12:49 am on Mar 21, 2003 (gmt 0)

WebmasterWorld Senior Member korkus2000 is a WebmasterWorld Top Contributor of All Time 10+ Year Member



This should work. Change NameOfCookie to the name of the cookie with the name.

<script>
function getCookie(NameOfCookie)
{
if(document.cookie.length > 0)
{
begin = document.cookie.indexOf(NameOfCookie+"=");
if(begin!= -1)
{
begin += NameOfCookie.length + 1;
end = document.cookie.indexOf(";",begin);
if(end == -1) end = document.cookie.length;
return unescape(document.cookie.substring(begin,end));
}
}
return null;
}
function delCookie(NameOfCookie)
{
if(getCookie(NameOfCookie)){
document.cookie = NameOfCookie +"=" +
";expires= Thu, 01-Jan-70 00:00:01 GMT";
}
}

</script>

Document.write("If you are not " + getCookie() + " then <a href='javascript:delCookie()'>click here</a>");

My js cookie ablities are quite rusty. You can find the original tutorial I changed here:
[scriptbreaker.com...]