I want to allow a client to write in an input on my website and have the text they enter be written to a file on my client-side(frontend) so I do not have to make an api call(to save time), rather I can just reference that file in the future. Is something like this possible?
Asked
Active
Viewed 60 times
-1
-
See this answer: http://stackoverflow.com/questions/21012580/is-it-possible-to-write-data-to-file-using-only-javascript – Marc Bacvanski Jan 21 '17 at 23:21
-
Use Local Storage. – Sebastian Simon Jan 21 '17 at 23:21
-
1Possible duplicate of [Is it possible to write data to file using only JavaScript?](http://stackoverflow.com/questions/21012580/is-it-possible-to-write-data-to-file-using-only-javascript) – Sebastian Simon Jan 21 '17 at 23:24
2 Answers
0
You can store some information from a user without an api call with local storage or a cookie. Try researching ng-storage. They make storing pretty easy.

mrtaz
- 446
- 1
- 6
- 16
-
isnt local storage temporary though - if the client deletes their local storage then the data will be gone right? – georgej Jan 21 '17 at 23:24
-
@georgej Of course. If the client deletes the file, the data will also be gone. Everything is temporary by that standard. – Sebastian Simon Jan 21 '17 at 23:25
-
Local storage has no expiration date. However the user can manually clear this in their browser. – mrtaz Jan 21 '17 at 23:26
0
You can store small amount of data in client's computer. Remember JavaScript runs on client machine.
// Store
localStorage.setItem("lastname", "Smith");
// Retrieve
document.getElementById("result").innerHTML = localStorage.getItem("lastname");
Read this for more information on localStorage object.
Be aware that it may not be supported by all the browsers though. If you want to play safe, store your text in cookies instead.

VHS
- 9,534
- 3
- 19
- 43
-
1I disagree with storing the text in cookies. If he doesn't need it on the server, then don't include in cookies which will be sent with every request. That just bloats up the request for no reason. localStorage has support all the way back to IE8, which covers most use cases I'd imagine – teaflavored Jan 21 '17 at 23:32