0

How can I save a textarea's information that contains more text than 4kb, in cookie's? I'm only open to Javascript, unfortunately. I can't tell the user that they can't use more than 4000 characters and set a limit is not acceptable in the situation. Tried to search through Google but it won't give me a result. Don't have to be friendly to any browser but Google Chrome.

Any ideas?

Xweque
  • 605
  • 1
  • 9
  • 29
  • 1
    Time to explore [`localStorage`](http://stackoverflow.com/tags/local-storage/info). – Rob W Jun 20 '12 at 14:20
  • What do you want to do with that 4KB text? – gdoron Jun 20 '12 at 14:20
  • I want to make a text editor that can save the text you enter, meaning it most lightly will be more than 4kb, a cookies max capacity. – Xweque Jun 20 '12 at 14:25
  • @Xweque Definitely use `localStorage`. The text editor's contents are not relevant in a request to the server. See also: [Are cookies fit for just client side usage?](http://stackoverflow.com/q/10413833?are-cookies-fit-for-just-client-side-usage) (scroll down a bit for non-localStorage fallbacks in older browsers). – Rob W Jun 20 '12 at 14:28

2 Answers2

1

Depending on your compatibility requirements you could use local storage. Up to 5MB if I remember correctly.

Currently, localStorage is supported by Firefox 3.5+, Safari 4+, IE8+, and Chrome

Per Salbark
  • 3,597
  • 1
  • 23
  • 24
0

Cookies are the old, way, you should look into using localStorage.

//Setting the value
var myList = document.getElementById('myToDoList');
localStorage.setItem('toDoData', myList.value);


//Reading the value
var myToDo = localStorage.getItem('toDoData');
if(myToDo){
    myList.value= myToDo;
}
epascarello
  • 204,599
  • 20
  • 195
  • 236