- Oct 9, 2002
- 28,298
- 1,236
- 136
I'm experimenting with cookies and I want to store the content of a textarea object. It's multi-line. When I store and retrieve the cookie, I get only the first line from the original textarea.
createCookie:
readCookie:
Can I make it so createCookie preserves line breaks in the value?
createCookie:
Code:
function createCookie(cookiename,value,days){
if(days){
var date=new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires="; expires="+date.toGMTString();
}else{var expires="";}
document.cookie=cookiename+"="+value+expires+"; path=/";
}
readCookie:
Code:
function readCookie(cookiename){
var nameEQ=cookiename+"=";
var ca=document.cookie.split(';');
for(var i=0;i<ca.length;i++){
var c=ca[i];
while(c.charAt(0)==' ') c=c.substring(1,c.length);
if(c.indexOf(nameEQ)==0){return c.substring(nameEQ.length,c.length);}
}
return "";
}
Can I make it so createCookie preserves line breaks in the value?
