在一个表单中设置和检查Cookies
资源介绍
第一个文件(cookie1.html)
<HTML>
<HEAD>
<SCRIPT LANGUAGE="Javascript">
<!--
function cookieRedirect(hasCookieURL, noCookieURL)
{
var currentCookie = document.cookie;
if (currentCookie.indexOf("formcomplete=yes") != -1) {
window.location = hasCookieURL;
} else {
window.location = noCookieURL;
}
}
// -->
</SCRIPT>
</HEAD>
<BODY>
<FORM NAME="docdownload">
<INPUT TYPE="BUTTON" VALUE="Download document"
onClick="cookieRedirect(doc.html, cookie2.html)">
</FORM>
</BODY>
</HTML>
第二个文件(cookie2.html ) <HTML>
<HEAD>
<SCRIPT LANGUAGE="JavaScript">
<!--
function sendForm(objForm)
{
cookieExpires = "Saturday, 01-Jan-03 00:00:00 GMT";
document.cookie = "formcomplete=yes; path=/";
// objForm.submit();
}
// -->
</SCRIPT>
</HEAD>
<BODY>
<FORM ACTION="test.html" NAME="info">
<TABLE>
<TR>
<TD>First name</TD>
<TD><INPUT TYPE="TEXT" NAME="firstname"></TD>
</TR>
<TD>Last name</TD>
<TD><INPUT TYPE="TEXT" NAME="lastname"></TD>
</TR>
<TR>
<TD>Address</TD>
<TD><INPUT TYPE="TEXT" NAME="address"></TD>
</TR>
<TR>
<TD>City</TD>
<TD><INPUT TYPE="TEXT" NAME="city"></TD>
</TR>
<TR>
<TD>State</TD>
<TD><INPUT TYPE="TEXT" NAME="state"></TD>
</TR>
<TR>
<TD>Zip</TD>
<TD><INPUT TYPE="TEXT" NAME="zip"></TD>
</TR>
</TABLE>
<INPUT TYPE="BUTTON" VALUE="Download document"
onClick="sendForm(document.testform)">
</FORM>
</BODY>
</HTML>
下面再给出需要用到的doc.html文件:
doc.html
<HTML>
<BODY>
<H3>This is the document</H3>
</BODY>
</HTML>