96turnerri
10-14-2003, 08:45 AM
hi im having a bit of trouble with a cookie i got in my site
i have this script for a cookie
<script>
mins = 60 /*number of minutes the cookie should persist*/
function writeCookie() {
/*write cookie*/
expdate = new Date()
expdate.setTime(expdate.getTime() + mins*60*1000);
document.cookie = "location="+window.location.href+"; expires=" + expdate.toGMTString() + "; path=/";
}
writeCookie();
</script>
which is in the head of every page and is read by
<script type="text/javascript">
function readCookie() {
/*cookie reading code*/
allcookies = document.cookie;
if (allcookies != "") {
/*check if a cookie named location exists*/
pos = allcookies.indexOf("location=");
if (pos != -1) {
var start = pos + 9;
var end = allcookies.indexOf(";", start);
if (end == -1) {
end = allcookies.length;
}
var value = unescape(allcookies.substring(start, end));
document.mistake.cookie.value = value;
}
}
}
readCookie();
</script>
which is displayed in a oneline box, i wish to do the same for this cookie which is placed on the homepage
but i cant get it to read on any other page can you please help?
<script type="text/javascript">
function getName(nm) {
userName = nm;
msg.close();
now = new Date();
exp = new Date(Date.parse(now) + (86400000*365));
SetCookie("userName", userName, exp);
window.location.reload();
}
function askUserName() {
msg = window.open("","msg","top=100,left=100,height=100,width=300,dependent=yes,resizable=yes");
msg.focus();
msg.document.writeln("<body onLoad='document.f1.nm.focus()' bgcolor='#000000'>");
msg.document.writeln("<form name='f1' onSubmit='window.opener.getName(this.nm.value);return false'>");
msg.document.writeln("<table>");
msg.document.writeln("<tr>");
msg.document.writeln("<td><font color='#FFFFFF'>Please enter your name: </font></td>");
msg.document.writeln("<td><input name='nm' type='text'></td>");
msg.document.writeln("</tr>");
msg.document.writeln("<tr>");
msg.document.writeln("<td> </td>");
msg.document.writeln("<td><input type='submit' value=' Submit '></td>");
msg.document.writeln("</tr>");
msg.document.writeln("</table>");
msg.document.writeln("</body>");
msg.document.close();
// window.location.reload();
return false;
}
function getCookieVal(offset) {
var endstr = document.cookie.indexOf (";", offset);
if (endstr == -1)
endstr = document.cookie.length;
return unescape(document.cookie.substring(offset, endstr));
}
function SetCookie(name,value,expires,path,domain,secure) {
document.cookie = name + "=" + escape (value) +
((expires) ? "; expires=" + expires.toGMTString() : "") +
((path) ? "; path=" + path : "") +
((domain) ? "; domain=" + domain : "") +
((secure) ? "; secure" : "");
}
function GetCookie(name) {
var arg = name + "=";
var alen = arg.length;
var clen = document.cookie.length;
var i = 0;
while (i < clen) {
var j = i + alen;
if (document.cookie.substring(i, j) == arg)
return getCookieVal(j);
i = document.cookie.indexOf(" ", i) + 1;
if (i == 0) break;
}
return null;
}
userName = GetCookie("userName");
if (!userName)
{askUserName();}
//else
// {alert("Welcome, " + userName + "!");}
function checkUser() {
if (document.getElementById)
{if (userName) document.getElementById("d1").style.visibility = "visible";}
else {
if (document.layers)
{if (userName) document.d1.visibility = "visible";}
else
{if (userName) document.all.d1.style.visibility = "visible";}
}
}
</script>
Thanks
Rich
i have this script for a cookie
<script>
mins = 60 /*number of minutes the cookie should persist*/
function writeCookie() {
/*write cookie*/
expdate = new Date()
expdate.setTime(expdate.getTime() + mins*60*1000);
document.cookie = "location="+window.location.href+"; expires=" + expdate.toGMTString() + "; path=/";
}
writeCookie();
</script>
which is in the head of every page and is read by
<script type="text/javascript">
function readCookie() {
/*cookie reading code*/
allcookies = document.cookie;
if (allcookies != "") {
/*check if a cookie named location exists*/
pos = allcookies.indexOf("location=");
if (pos != -1) {
var start = pos + 9;
var end = allcookies.indexOf(";", start);
if (end == -1) {
end = allcookies.length;
}
var value = unescape(allcookies.substring(start, end));
document.mistake.cookie.value = value;
}
}
}
readCookie();
</script>
which is displayed in a oneline box, i wish to do the same for this cookie which is placed on the homepage
but i cant get it to read on any other page can you please help?
<script type="text/javascript">
function getName(nm) {
userName = nm;
msg.close();
now = new Date();
exp = new Date(Date.parse(now) + (86400000*365));
SetCookie("userName", userName, exp);
window.location.reload();
}
function askUserName() {
msg = window.open("","msg","top=100,left=100,height=100,width=300,dependent=yes,resizable=yes");
msg.focus();
msg.document.writeln("<body onLoad='document.f1.nm.focus()' bgcolor='#000000'>");
msg.document.writeln("<form name='f1' onSubmit='window.opener.getName(this.nm.value);return false'>");
msg.document.writeln("<table>");
msg.document.writeln("<tr>");
msg.document.writeln("<td><font color='#FFFFFF'>Please enter your name: </font></td>");
msg.document.writeln("<td><input name='nm' type='text'></td>");
msg.document.writeln("</tr>");
msg.document.writeln("<tr>");
msg.document.writeln("<td> </td>");
msg.document.writeln("<td><input type='submit' value=' Submit '></td>");
msg.document.writeln("</tr>");
msg.document.writeln("</table>");
msg.document.writeln("</body>");
msg.document.close();
// window.location.reload();
return false;
}
function getCookieVal(offset) {
var endstr = document.cookie.indexOf (";", offset);
if (endstr == -1)
endstr = document.cookie.length;
return unescape(document.cookie.substring(offset, endstr));
}
function SetCookie(name,value,expires,path,domain,secure) {
document.cookie = name + "=" + escape (value) +
((expires) ? "; expires=" + expires.toGMTString() : "") +
((path) ? "; path=" + path : "") +
((domain) ? "; domain=" + domain : "") +
((secure) ? "; secure" : "");
}
function GetCookie(name) {
var arg = name + "=";
var alen = arg.length;
var clen = document.cookie.length;
var i = 0;
while (i < clen) {
var j = i + alen;
if (document.cookie.substring(i, j) == arg)
return getCookieVal(j);
i = document.cookie.indexOf(" ", i) + 1;
if (i == 0) break;
}
return null;
}
userName = GetCookie("userName");
if (!userName)
{askUserName();}
//else
// {alert("Welcome, " + userName + "!");}
function checkUser() {
if (document.getElementById)
{if (userName) document.getElementById("d1").style.visibility = "visible";}
else {
if (document.layers)
{if (userName) document.d1.visibility = "visible";}
else
{if (userName) document.all.d1.style.visibility = "visible";}
}
}
</script>
Thanks
Rich