JavaScript: Cookie setzen und auslesen
Veröffentlicht: 28. Juni 2005
<html> <head> <title>Cookietest</title> <script type="TEXT/JAVASCRIPT"> Verfallsdatum = new Date; Verfallsdatum.setMonth(Verfallsdatum.getMonth()+6) nachname=""; if (document.cookie !="") { nachname = document.cookie.split("_")[1] vorname = document.cookie.split("_")[2] abteilung = document.cookie.split("_")[3] } function CookieEinrichten() { nachname=document.Formular.nachnamefeld.value; vorname=document.Formular.vornamefeld.value; abteilung=document.Formular.abteilungfeld.value; document.cookie="_" +nachname +"_" +vorname +"_" +abteilung +"_" +";expires="+Verfallsdatum.toGMTString() } function CookieAusgabe() { if (document.cookie !="") { document.Formular.nachnamefeld.value = nachname document.Formular.vornamefeld.value = vorname document.Formular.abteilungfeld.value = abteilung } } </script> </head> <body onLoad="CookieAusgabe()"> <form name="Formular"> <b>Nachname:</b><input type="text" name="nachnamefeld" onBlur="CookieEinrichten()" size=10/><br /> <b>Vorname:</b><input type="text" name="vornamefeld" onBlur="CookieEinrichten()" size=10/><br /> <b>Abteilung:</b><input type="text" name="abteilungfeld" onBlur="CookieEinrichten()" size=10/><br /> </form> </body> </html> |