Tôi đang cố gắng đặt nhiều cookie trong document.cookie
, nhưng tiếc là chỉ có một cookie được thêm.Đặt nhiều cookie trong Javascript
Tôi biết có nhiều ví dụ hiển thị trên 'Net để thiết lập các loại cookie này và tôi đã theo dõi một trong số chúng. Nhưng tôi vẫn không thể đặt ra điều đó. Tôi đã theo dõi số link này để đặt cookie của tôi.
Mã của tôi:
function setCookie(start_time,end_session_time,total_time,flag,count){
var cookie_string = "start_time="+start_time;;
if(end_session_time) {
cookie_string +="; end_session_time="+end_session_time;
}
if(total_time){
cookie_string +="; total_time="+total_time;
}
if(flag){
cookie_string +="; flag="+flag;
}
if(count){
cookie_string +="; count="+count;
}
document.cookie =cookie_string ;
console.log(cookie_string);
console.log("document.cookie ="+ document.cookie);
}
Các Output:
cookie_string :: start_time=1369926508266; flag=1; count=1
document.cookie =start_time=1369926508266;
Xem http://www.quirksmode.org/js/cookies.html – Barmar