0
簡單的cookie記錄,我有7個複選框,kp1-kp7 setCookies,每次點擊它們中的一些時,都會創建cookie。問題是,當我關閉瀏覽器並重新打開頁面(本地)時,Cookie消失,它們不在那裏。 當我點擊複選框,並創建的cookie,他創建picture to prove itCookie始終過期instanlty
window.onload = function(){
if(document.cookie.length != 0){
var nizKolacica = document.cookie.split("; ");
var nizVrednostiKolacica = nizKolacica.split("=");
// 0 - c1tip
// 1 - tekst/cb
// 2 - c2tip
// 3 - tekst/cb
if(nizVrednostiKolacica[1] == "tekst" || nizVrednostiKolacica.length == 0){
document.getElementById("kp1").checked = true;
}else{
document.getElementById("kp1").checked = false;
}
if(nizVrednostiKolacica[3] == "tekst" || nizVrednostiKolacica.length == 0){
document.getElementById("kp2").checked = true;
}else{
document.getElementById("kp2").checked = false;
}
if(nizVrednostiKolacica[5] == "tekst" || nizVrednostiKolacica.length == 0){
document.getElementById("kp3").checked = true;
}else{
document.getElementById("kp3").checked = false;
}
if(nizVrednostiKolacica[7] == "tekst" || nizVrednostiKolacica.length == 0){
document.getElementById("kp4").checked = true;
}else{
document.getElementById("kp4").checked = false;
}
if(nizVrednostiKolacica[9] == "tekst" || nizVrednostiKolacica.length == 0){
document.getElementById("kp5").checked = true;
}else{
document.getElementById("kp5").checked = false;
}
if(nizVrednostiKolacica[12] == "tekst" || nizVrednostiKolacica.length == 0){
document.getElementById("kp6").checked = true;
}else{
document.getElementById("kp6").checked = false;
}
if(nizVrednostiKolacica[12] == "tekst" || nizVrednostiKolacica.length == 0){
document.getElementById("kp7").checked = true;
}else{
document.getElementById("kp7").checked = false;
}
}
}
var kp1 = false;
var kp2 = false;
var kp3 = false;
var kp4 = false;
var kp5 = false;
var kp6 = false;
var kp7 = false;
function kp1SetCoockie(){
kp1 = !kp1;
if(kp1){
document.cookie = "c1tip=tekst;expires=Sun, 25 Jun 2017 8:00:00 UTC";
}else{
document.cookie ="c1tip=cb";
}
}
function kp2SetCoockie(){
kp2 = !kp2;
if(kp2){
document.cookie = "c2tip=tekst;max-age=3600";
}else{
document.cookie ="c2tip=cb";
}
}
function kp3SetCoockie(){
kp3 = !kp3;
if(kp3){
document.cookie = "c3tip=tekst;max-age=3600; path=/";
}else{
document.cookie ="c3tip=cb";
}
}
function kp4SetCoockie(){
kp4 = !kp4;
if(kp4){
document.cookie = "c4tip=tekst;max-age=3600; path=/";
}else{
document.cookie ="c4tip=cb";
}
}
function kp5SetCoockie(){
kp5 = !kp5;
if(kp5){
document.cookie = "c5tip=tekst;max-age=3600; path=/";
}else{
document.cookie ="c5tip=cb";
}
}
function kp6SetCoockie(){
kp6 = !kp6;
if(kp6){
document.cookie = "c6tip=tekst;max-age=3600; path=/";
}else{
document.cookie ="c6tip=cb";
}
}
function kp7SetCoockie(){
kp7 = !kp7;
if(kp7){
document.cookie = "c7tip=tekst;max-age=3600; path=/";
}else{
document.cookie ="c7tip=cb";
}
}
我做了kp1,但它不起作用 – Nosorog
哦,我錯過了第一個......嗯,定義路徑? – Schlumpf
嘗試過它在kp3:D – Nosorog