Getting a file out of a local web page

45 views Asked by At

This is what I'd like to achieve from a local page:

  • Enter data in a textbox
  • Transform the data (the outcome may be not a text file)
  • Get the transformed data back.

Directly writing on a local file is clearly out of question for security reasons. I know HTML5 has a FileWriter API but it's not supported on many browsers (and I think for a good reason).

I thought about creating the data as the content of one of the page elements (say a <DIV>) but then I am at loss on how to send that data back.

In essence, I feel I had to mimic the usual http request/response process while always remaining on the client side.

I start thinking that this is not possible at all, any suggestion?

1

There are 1 answers

0
klarki On

One way that would take you near your desired outcome is by using data: URI scheme (http://en.wikipedia.org/wiki/Data_URI_scheme)

window.open("data:text/plain;charset=utf-8,"+textToPrint); 

That opens a new tab with the text you want to save, you just need to click save or ctrl+s to save the text in a .txt file.