Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #21254
| From | Ken <usenet-so@abdiassoftware.com> |
|---|---|
| Newsgroups | comp.lang.javascript |
| Subject | Re: Write variables to file? |
| Date | 2013-09-10 12:31 -0500 |
| Organization | Abdias Software |
| Message-ID | <l0nl37$ovm$1@speranza.aioe.org> (permalink) |
| References | <8eqdnQgNPt5ncrPPnZ2dnUVZ5hSdnZ2d@giganews.com> |
On 10.09.2013 05:10, Robert Crandal wrote:> Can I use Javascript to write data into a text file on the > client machine? I tried experiement with cookie objects, but this > didn't produce the results that I wanted. > > My webpage will display a form with text fields. The user > will type in data. I then want to save this data somehow on > the client machine. Simple answer: no. Imagine what harm a "bad hacker" could do if you could write directly to a user's ordinary file system. All the direct storage mechanims in a browser are sand-boxed, being Web Storage (localStorage and sessionStorage), File API (currently only supported in Chrome), Indexed DB or WebSQL (latter now deprecated but still widely supported). You can however provide the text file as a data-uri and make it available from a link with the new download attribute set so when a user clicks the link a save as file requester will appear allowing user to save the file initially set with the name you set. You can encode data-uri's as Base64 or printed-quotable. You can also use a Blob object to retrieve a link from. You can create this element dynamically using document.createElement() (and hint: you can also produce a click event for it) or simply set the download and href attributes on an existing a element at run-time. -- Ken Fyrstenberg Abdias Software http://abdiassoftware.com/ (remove usenet- from address)
Back to comp.lang.javascript | Previous | Next — Previous in thread | Find similar | Unroll thread
Write variables to file? "Robert Crandal" <rcranz143101@gmail.com> - 2013-09-10 03:10 -0700
Re: Write variables to file? Denis McMahon <denismfmcmahon@gmail.com> - 2013-09-10 10:24 +0000
Re: Write variables to file? Richard Maher <maher_rjSPAMLESS@hotmail.com> - 2013-09-10 18:42 +0800
Re: Write variables to file? Martin Honnen <mahotrash@yahoo.de> - 2013-09-10 12:45 +0200
Re: Write variables to file? JJ <duh@nah.meh> - 2013-09-10 18:13 +0700
Re: Write variables to file? Ken <usenet-so@abdiassoftware.com> - 2013-09-10 12:15 -0500
Re: Write variables to file? dhtml <dhtmlkitchen@gmail.com> - 2013-09-30 00:44 -0700
Re: Write variables to file? Ken <usenet-so@abdiassoftware.com> - 2013-09-10 12:31 -0500
csiph-web