You are here: irt.org | FAQ | JavaScript | Cookie | Q770 [ previous next ]
In the first page place:
<HTML>
<HEAD>
<SCRIPT LANGUAGE="JavaScript"><!--
function Get_Cookie(name) {
var start = document.cookie.indexOf(name+"=");
var len = start+name.length+1;
if ((!start) && (name != document.cookie.substring(0,name.length))) return null;
if (start == -1) return null;
var end = document.cookie.indexOf(";",len);
if (end == -1) end = document.cookie.length;
return unescape(document.cookie.substring(len,end));
}
function get() {
email = Get_Cookie("email");
if (email == null) {
location.href = 'test2.htm';
}
}
//--></SCRIPT>
</HEAD>
<BODY onLoad="get()">
...
</BODY>
</HTML>And then on welcome.htm:
<HTML>
<HEAD>
<SCRIPT LANGUAGE="JavaScript"><!--
function Set_Cookie(name,value,expires,path,domain,secure) {
document.cookie = name + "=" +escape(value) +
( (expires) ? ";expires=" + expires.toGMTString() : "") +
( (path) ? ";path=" + path : "") +
( (domain) ? ";domain=" + domain : "") +
( (secure) ? ";secure" : "");
}
var today = new Date();
var expires = new Date(today.getTime() + (56 * 86400000));
function set() {
Set_Cookie("email",document.logonForm.email.value,expires);
}
//--></SCRIPT>
</HEAD>
<BODY>
<FORM NAME="logonForm" onSubmit="return set();">
<P>Email: <INPUT TYPE="INPUT" NAME="email">
<P><INPUT TYPE="RESET"> <INPUT TYPE="SUBMIT">
</FORM>
</BODY>
</HTML>