第一个文件(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>
<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">
<TABLE>
<TR>
<TD>First name</TD>
<TD><INPUT TYPE="TEXT"></TD>
</TR>
<TD>Last name</TD>
<TD><INPUT TYPE="TEXT"></TD>
</TR>
<TR>
<TD>Address</TD>
<TD><INPUT TYPE="TEXT"></TD>
</TR>
<TR>
<TD>City</TD>
<TD><INPUT TYPE="TEXT"></TD>
</TR>
<TR>
<TD>State</TD>
<TD><INPUT TYPE="TEXT"></TD>
</TR>
<TR>
<TD>Zip</TD>
<TD><INPUT TYPE="TEXT"></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>
为了测试一下这个功能,你可以打开cookie1.html并点击中按钮,你将被带到表单网页。如果你回到cookie1.html文件并点击按钮你就回直接连到文档去。