begin process at 2010 02 10 00:19:18
  Trouver un code source :
 
dans
 
Accueil > 

Code

 > 

Cookies

 > UNE LISTE GÉRÉE PAR COOKIES

UNE LISTE GÉRÉE PAR COOKIES


 Information sur la source

Note :
9 / 10 - par 4 personnes
9,00 / 10

  • 1

  • 2

  • 3

  • 4

  • 5

  • 6

  • 7

  • 8

  • 9

  • 10
Catégorie :Cookies Niveau :Initié Date de création :06/06/2004 Date de mise à jour :06/06/2004 20:12:57 Vu :5 510

Auteur : Nicoboss

Ecrire un message privé
Site perso
Commentaire sur cette source (3)
Ajouter un commentaire et/ou une note

 Description

Ce script permet d'ajouter et d'enlever des "titres" (phrases ou suite de mots) entièrement grâces aux cookies.
Marche entièrement sur ie et plus ou moins sur Mozilla

Source

  • <html>
  • <head>
  • <SCRIPT LANGUAGE="JavaScript">
  • <!-- début
  • var expDays = 30;
  • var exp = new Date();
  • exp.setTime(exp.getTime() + (expDays*24*60*60*1000));
  • var ShowCount = 0;
  • var SwapColour;
  • function ListToDoItems() {
  • var NumToDoItems = GetCookie('PT_NumToDoList');
  • var i;
  • var ToDoItem;
  • if (NumToDoItems == null) {
  • NumToDoItems = 0;
  • }
  • ShowCount = 0; SwapColour = 0;
  • for (i=1; i <= NumToDoItems; i++) {
  • ToDoItem = GetCookie('PT_ToDoItem'+i);
  • if (ToDoItem != null) {
  • PrintItem(ToDoItem, i);
  • }
  • }
  • }
  • function DeleteItem(Count) {
  • DeleteCookie('PT_ToDoItem'+Count);
  • window.location = window.location;
  • }
  • function PrintItem (ToDoItem, Count) {
  • var color = "";
  • SwapColour = 1 - SwapColour;
  • if (SwapColour==1) {color = "bgcolor='#c0c0c0'"} ;
  • ShowCount++;
  • document.write("<tr " + color + ">");
  • document.write("<td width=10% align=center valign=top><small><b>"+ShowCount);
  • document.write("<td width=75% align=left ><small>"+ToDoItem);
  • document.write("<td width=15% align=center><small>"+"<a href='javascript:DeleteItem(" + Count +
  • ")'>Supprimer</a>");
  • }
  • function AddItem() {
  • var NumToDoItems = GetCookie('PT_NumToDoList');
  • var i;
  • var ToDoItem;
  • if (NumToDoItems == null) {
  • NumToDoItems = 0;
  • }
  • ToDoItem = prompt("Entrer un nouveau titre");
  • if ((ToDoItem != null) && (ToDoItem != "undefined" )) {
  • NumToDoItems++;
  • SetCookie('PT_ToDoItem'+NumToDoItems, ToDoItem, exp);
  • SetCookie('PT_NumToDoList',NumToDoItems, exp);
  • window.location = window.location;
  • }
  • }
  • function set() {
  • VisitorName = prompt("Qui êtes vous?");
  • SetCookie ('VisitorName', VisitorName, exp);
  • SetCookie ('WWHCount', 0, exp);
  • SetCookie ('WWhenH', 0, exp);
  • }
  • function getCookieVal (offset) {
  • var endstr = document.cookie.indexOf (";", offset);
  • if (endstr == -1)
  • endstr = document.cookie.length;
  • return unescape(document.cookie.substring(offset, endstr));
  • }
  • function GetCookie (name) {
  • var arg = name + "=";
  • var alen = arg.length;
  • var clen = document.cookie.length;
  • var i = 0;
  • while (i < clen) {
  • var j = i + alen;
  • if (document.cookie.substring(i, j) == arg)
  • return getCookieVal (j);
  • i = document.cookie.indexOf(" ", i) + 1;
  • if (i == 0) break;
  • }
  • return null;
  • }
  • function SetCookie (name, value) {
  • var argv = SetCookie.arguments;
  • var argc = SetCookie.arguments.length;
  • var expires = (argc > 2) ? argv[2] : null;
  • var path = (argc > 3) ? argv[3] : null;
  • var domain = (argc > 4) ? argv[4] : null;
  • var secure = (argc > 5) ? argv[5] : false;
  • document.cookie = name + "=" + escape (value) +
  • ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
  • ((path == null) ? "" : ("; path=" + path)) +
  • ((domain == null) ? "" : ("; domain=" + domain)) +
  • ((secure == true) ? "; secure" : "");
  • }
  • function DeleteCookie (name) {
  • var exp = new Date();
  • exp.setTime (exp.getTime() - 1);
  • var cval = GetCookie (name);
  • document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
  • }
  • // fin -->
  • </script>
  • </head>
  • <body>
  • <b><center><big>Dans la liste, il y a le(s) titre(s) :</big><center></b>
  • <hr><br>
  • <table width=100%>
  • <SCRIPT LANGUAGE="JavaScript">
  • <!-- début
  • ListToDoItems();
  • // fin -->
  • </SCRIPT>
  • </table>
  • <br><hr>
  • <center>
  • <a href="javascript:AddItem()">Ajouter un titre</a>
  • </center>
  • </body>
  • </html>
<html>
<head>

<SCRIPT LANGUAGE="JavaScript">

<!-- début
var expDays = 30;
var exp = new Date(); 
exp.setTime(exp.getTime() + (expDays*24*60*60*1000));
var ShowCount = 0;
var SwapColour;
function ListToDoItems() {
var NumToDoItems = GetCookie('PT_NumToDoList');
var i;
var ToDoItem;
if (NumToDoItems == null) {
NumToDoItems = 0;
}
ShowCount = 0; SwapColour = 0;
for (i=1; i <= NumToDoItems; i++) {
ToDoItem = GetCookie('PT_ToDoItem'+i);
if (ToDoItem != null) {
PrintItem(ToDoItem, i);
      }
   }
}
function DeleteItem(Count) {
DeleteCookie('PT_ToDoItem'+Count);
window.location = window.location;
}
function PrintItem (ToDoItem, Count) {
var color = "";
SwapColour = 1 - SwapColour;
if (SwapColour==1) {color = "bgcolor='#c0c0c0'"} ;
ShowCount++;
document.write("<tr " + color + ">");
document.write("<td width=10% align=center valign=top><small><b>"+ShowCount);
document.write("<td width=75% align=left  ><small>"+ToDoItem);
document.write("<td width=15% align=center><small>"+"<a href='javascript:DeleteItem(" + Count + 

")'>Supprimer</a>");
}
function AddItem() {
var NumToDoItems = GetCookie('PT_NumToDoList');
var i;
var ToDoItem;
if (NumToDoItems == null) {
NumToDoItems = 0;
}
ToDoItem = prompt("Entrer un nouveau titre");
if ((ToDoItem != null) && (ToDoItem != "undefined" )) {
NumToDoItems++;
SetCookie('PT_ToDoItem'+NumToDoItems, ToDoItem, exp);
SetCookie('PT_NumToDoList',NumToDoItems, exp);
window.location = window.location;
   }
}
function set() {
VisitorName = prompt("Qui êtes vous?");
SetCookie ('VisitorName', VisitorName, exp);
SetCookie ('WWHCount', 0, exp);
SetCookie ('WWhenH', 0, exp);
}
function getCookieVal (offset) {  
var endstr = document.cookie.indexOf (";", offset);  
if (endstr == -1)    
endstr = document.cookie.length;  
return unescape(document.cookie.substring(offset, endstr));
}
function GetCookie (name) {  
var arg = name + "=";  
var alen = arg.length;  
var clen = document.cookie.length;  
var i = 0;  
while (i < clen) {    
var j = i + alen;    
if (document.cookie.substring(i, j) == arg)      
return getCookieVal (j);    
i = document.cookie.indexOf(" ", i) + 1;    
if (i == 0) break;   
}  
return null;
}
function SetCookie (name, value) {  
var argv = SetCookie.arguments;  
var argc = SetCookie.arguments.length;  
var expires = (argc > 2) ? argv[2] : null;  
var path = (argc > 3) ? argv[3] : null;  
var domain = (argc > 4) ? argv[4] : null;  
var secure = (argc > 5) ? argv[5] : false;  
document.cookie = name + "=" + escape (value) + 
((expires == null) ? "" : ("; expires=" + expires.toGMTString())) + 
((path == null) ? "" : ("; path=" + path)) +  
((domain == null) ? "" : ("; domain=" + domain)) +    
((secure == true) ? "; secure" : "");
}
function DeleteCookie (name) {  
var exp = new Date();  
exp.setTime (exp.getTime() - 1);  
var cval = GetCookie (name);  
document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
}
//  fin -->
</script>

</head>

<body>

<b><center><big>Dans la liste, il y a le(s) titre(s) :</big><center></b>
<hr><br>
<table width=100%>
<SCRIPT LANGUAGE="JavaScript">
<!-- début
ListToDoItems();
//  fin -->
</SCRIPT>
</table>
<br><hr>
<center>
<a href="javascript:AddItem()">Ajouter un titre</a>
</center>

</body>
</html>

 Conclusion

Ce script ne marche pas forcément sous Mozilla...


 Sources du même auteur

Source avec Zip Source avec une capture PRELOAD D'UNE PAGE AVEC BARRE DE PROGRESSION
NOTATION DE SITES
PETIT QUIZ
Source avec Zip CRÉATEUR SIMPLE DE PAGE WEB (EN ANGLAIS)
Source avec Zip PETIT SCRIPT DU GENRE MOTEUR DE RECHERCHE AVEC MOTS-CLÉS, NO...

 Sources de la même categorie

Source avec Zip LES COOKIES ET JAVASCRIPT par Zestyr
COOKIES EN JAVASCRIPT par CodeurleGeek
Source avec Zip MULTI-BLOC-NOTE(AVEC COOKIES!) par DomJ
Source avec Zip LES VINGTS JOLIS COOKIES par cornofulgur
Source avec Zip AJOUTER, SUPPRIMER, LIRE COOKIE! par DomJ

Commentaires et avis

Commentaire de frop01 le 25/08/2004 19:51:36

Super ce code et je crois que je vais m'en servir plutard!

allez 10/10 ;)

Commentaire de DomJ le 12/03/2006 03:47:03

Je sais pas quoi dire... Les deux: Bravo et Merci!!! 10/10!

Commentaire de XelectroX le 16/09/2007 11:25:26

Alors là, ce code est excellent !!
Et en plus, il marche sur Firefox 2.0.0.6 :)
Je vais m'en servir !

10/10

 Ajouter un commentaire




Nos sponsors


Sondage...

CalendriCode

Février 2010
LMMJVSD
1234567
891011121314
15161718192021
22232425262728

Consulter la suite du CalendriCode

 
Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils.
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 0,530 sec (3)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales