MANIPULACIA S COOKIE

ID
Nazov / Name:
Popis / Description:
Dlzka / Length:
Testovane pod / Tested under:

 

073
p073.html / p073.zip
Zapis a citanie cookie
3266b
NN 4.04, IE 4.0

UKAZKA / CLICK HERE

Zdrojovy tvar / Source code:

<HTML> <HEAD> <TITLE> JavaScript DESTINATION - P073 </TITLE> <SCRIPT LANGUAGE="Javascript"> <!-- function expiryDate() { var yearsMonths = "JANFEBMARAPRMAYJUNJULAUGSEPOCTNOVDEC"; var now = new Date(); var nLyear = 1900 + now.getYear(); var nLmonthABR = yearsMonths.substring( now.getMonth() * 3, now.getMonth() * 3 + 3 ); var nLdayOfMonth = now.getDate(); nLdayOfMonth += 1; if ( nLdayOfMonth > 28 ) nLdayOfMonth = 1; return '' + nLdayOfMonth + '-' + nLmonthABR + '-' + nLyear + ' GMT'; } function cookieDoesFileExist() { if ( document.cookie ) return true; else return false; } function cookieDoesItExist(cookieName) { if ( cookieDoesFileExist() ) if ( document.cookie.indexOf( cookieName + "=" ) != -1 ) return true; return false; } function cookieCreate( cookieName, cookieValue, cookieExpires ) { var today = new Date(); var nLyear = 3 + today.getYear(); if ( cookieExpires == 'forever' ) cookieExpires = "01-APR-" + nLyear + " GMT" document.cookie = cookieName + "=" + cookieValue + "; expires=" + cookieExpires; if( cookieDoesItExist( cookieName ) ) return true; else return false; } function cookieReadValue(cookieName) { var countbegin = (document.cookie.indexOf(cookieName+"=") + cookieName.length+1); var countend = countbegin + document.cookie.substring( countbegin ).indexOf(";"); if ( countend < countbegin ) countend = document.cookie.length; return document.cookie.substring( countbegin, countend); } function cookieDoesItExistIfNotCreate(cookieName,cookieValue,cookieExpires) { if ( cookieDoesItExist(cookieName) == false ) return cookieCreate(cookieName,cookieValue,cookieExpires); return true; } function cookieExampleRead() { if ( cookieDoesItExist( document.exampleForm.cookieName.value ) ) { document.exampleForm.cookieValue.value = cookieReadValue( document.exampleForm.cookieName.value ); document.exampleForm.cookieMessage.value = "Cookie bol precitany"; } else { document.exampleForm.cookieValue.value = ''; document.exampleForm.cookieMessage.value = 'Neznamy Cookie'; } } function cookieExampleSave() { if ( cookieCreate( document.exampleForm.cookieName.value, document.exampleForm.cookieValue.value, expiryDate() ) ) document.exampleForm.cookieMessage.value = 'Cookie bol zapisany'; else document.exampleForm.cookieMessage.value = 'Cookie nebol zapisany'; } // --> </SCRIPT> </HEAD> <BODY> <pre> <FORM NAME="exampleForm"> Nazov Cookie : <INPUT NAME="cookieName" TYPE="Text" SIZE="32"> Hodnota Cookie: <INPUT NAME="cookieValue" TYPE="Text" SIZE="32"> Sprava : <INPUT NAME="cookieMessage" TYPE="Text" SIZE="32"> <INPUT NAME="saveButton" TYPE="button" VALUE="Zapis" onClick="cookieExampleSave()"><INPUT NAME="readButton" TYPE="button" VALUE="Precitaj" onClick="cookieExampleRead()"> </FORM> </pre> </BODY> </HTML>
[ Navrat / BACK ]