javascript-cookie?
My cookie says welcome but not output the name. I tried including the name with + name, but it does not output?
<html>
<head>
<title>New Page 1</title>
<script type ="text/javascript">
function getCookie(name)
{
if (document.cookie.length > 0)
{
s = document.cookie.indexOf("name =");
if (s != -1)
{
s2 = s + 5;
e = document.cookie.indexOf(";", s2);
if (e == -1)
e = (document.cookie.length);
return unescape (document.cookie.substring(s2, e));
}
}
return "";
}
function set_cookie(name, value, exp_y, exp_m, exp_d)
{
cookie_string = name + "=" + escape(value);
if (exp_y)
{
var expires = new Date(exp_y, exp_m, exp_d);
cookie_string += "; expires=" + expires.toUTCString();
}
}
function check_user()
{ name = getCookie('name'); if (name!=null)
alert("Welcome back")
else { name= prompt("Enter your name")
if (name!=null && name!="") { cookie_create("name",name,7)
}
}
}
</script>
</head>
<body onLoad="check_user()">
</body>
</html>
|