Ciao
<script>
<!--
// (C) by Massimo61 massimo61@iol.it
var nomecookie="esempio";
function getCookieVal (offsetb) {
var endstrb = document.cookie.indexOf (";", offsetb);
if (endstrb == -1)
endstrb = document.cookie.length;
return unescape(document.cookie.substring(offsetb, endstrb));
}
function GetCookie (searchcookie) {
var argb = searchcookie + "=";
var alenb = argb.length;
var clenb = document.cookie.length;
var ib = 0;
while (ib < clenb) {
var jb = ib + alenb;
if (document.cookie.substring(ib, jb) == argb)
return getCookieVal (jb);
ib = document.cookie.indexOf(" ", ib) + 1;
if (ib == 0) break;
}
return null;
}
writecookie = GetCookie(nomecookie);
if (writecookie=="" || writecookie==null){
cookie="no"
}
else
cookie="yes";
if (cookie=="no"){
var win=window.open('pagina.html','','width=220,height =220,scrollbars=no,top=200,left=200');
}
if (cookie=="no"){
nomecookie = "esempio"
pathname = location.pathname;
myDomain = pathname.substring(0,pathname.lastIndexOf('/')) +'/';
var largeExpDate = new Date ();
largeExpDate.setTime(largeExpDate.getTime()+(1 * 24 * 3600 * 1000));
SetCookie(nomecookie,win,largeExpDate,myDomain);
}
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" : "");
}
// -->
</script>
Adesso la scadenza del cookie è dopo un giorno:
largeExpDate.setTime(largeExpDate.getTime()+(1 * 24 * 3600 * 1000));
1 = giorni
24= ore del giorno
3600 = secondi di un'ora
1000 = millisecondi
Se deve scadere dopo un'ora:
largeExpDate.setTime(largeExpDate.getTime()+(1 * 1 * 3600 * 1000));
Dopo un mese:
largeExpDate.setTime(largeExpDate.getTime()+(31 * 24 * 3600 * 1000));
Massimo