选择显示字体大小

javascript 实例--在表单中设置和检查cookies


cookie是一小段由浏览器储存起来帮助识别用户身份的信息。在一个表单中设置和检查cookies的实现需要两个文件来完成。第一个文件为cookie1.html,这个文件需要有一些机理(下面例子的一个按钮)来检查是否有一个cookie存在,然后再重定向至表单网页或者文档下载网页。而第二个文件,即表单网页(cookie2.html),也是和重要的因为你将要在上面使用一点点javascript来设置cookie,这个设置是在提交表单之前做的。下面给出这文件:

第一个文件(cookie1.html

<html>

<head>

<script language=&quot;javascript&quot;>

<!--

function cookieredirect(hascookieurl, nocookieurl)

{

var currentcookie = document.cookie;

if (currentcookie.indexof(&quot;formcomplete=yes&quot;) != -1) {

window.location = hascookieurl;

} else {

window.location = nocookieurl;

}

}

// -->

</script>

</head>

<body>

<form name=&quot;docdownload&quot;>

<input type=&quot;button&quot; value=&quot;download document&quot;

onclick=&quot;cookieredirect('doc.html', 'cookie2.html')&quot;>

</form>

</body>

</html>
第二个文件(cookie2.html ) <html>

<head>

<script language=&quot;javascript&quot;>

<!--

function sendform(objform)

{

cookieexpires = &quot;saturday, 01-jan-03 00:00:00 gmt&quot;;

document.cookie = &quot;formcomplete=yes; path=/&quot;;

// objform.submit();

}

// -->

</script>

</head>

<body>

<form action=&quot;test.html&quot; name=&quot;info&quot;>

<table>

<tr>

<td>first name</td>

<td><input type=&quot;text&quot; name=&quot;firstname&quot;></td>

</tr>

<td>last name</td>

<td><input type=&quot;text&quot; name=&quot;lastname&quot;></td>

</tr>

<tr>

<td>address</td>

<td><input type=&quot;text&quot; name=&quot;address&quot;></td>

</tr>

<tr>

<td>city</td>

<td><input type=&quot;text&quot; name=&quot;city&quot;></td>

</tr>

<tr>

<td>state</td>

<td><input type=&quot;text&quot; name=&quot;state&quot;></td>

</tr>

<tr>

<td>zip</td>

<td><input type=&quot;text&quot; name=&quot;zip&quot;></td>

</tr>

</table>

<input type=&quot;button&quot; value=&quot;download document&quot;

onclick=&quot;sendform(document.testform)&quot;>

</form>

</body>

</html>

下面再给出需要用到的doc.html文件:

doc.html

<html>

<body>

<h3>this is the document</h3>

</body>

</html>

为了测试一下这个功能,你可以打开cookie1.html并点击中按钮,你将被带到表单网页。如果你回到cookie1.html文件并点击按钮你就回直接连到文档去。

  


 


关键字 本文所属关键字

相关 与本文相关文章

分类 所有文章关键字导航

源码编程相关

Java   Asp   PHP   .Net   XML   C/C++   CGI   VB   Jsp   J2ee   J2se   J2me   EJB   Servlet   Tomcat   Resin   Struts   Weblogic   Eclipse   ANT   GUI   JMS   Web servise   IDEA   Webphere   Hibernate   Spring   Jboss   Applet   Swing   Socket   Javamail   Perl   Ajax   P2P   安全   模式   框架   测试   开源   游戏

SQL数据库相关

My-SQL   Ms-SQL   Access   DB2   Oracle   Sybase   SQLserver   索引   存储过程   加密   数据库   分页   视图  

手机无线相关

3G   Wap   CDMA   GRPS   GSM   IVR   彩信   短信   无线   增值业务

网页设计制作相关

HTML   CSS   网页配色   网页特效   Javascript   VBscript   Dreamweaver   Frontpage   JS   Web   网站设计

网站建设推广相关

建站经验   网站优化   网站排名   推广   Alexa

操作系统/服务器相关

Windows XP   Windows 2000   Windows 2003   Windows Me   Windows 9.x   Linux   UNIX   注册表   操作系统   服务器   应用服务器

图形图像多媒体相关

Photoshop   Fireworks   Flash   Coreldraw   Illustrator   Freehand   Photoimpact   多媒体   图形图像

标准 网站致力的规范

Valid CSS!

无不良内容,无不良广告,无恶意代码

Valid XHTML 1.0 Transitional

creativecommons