4
<html>
<body>
<form>
    <textarea></textarea>
    <input type=submit value="Save"></input>
</form>
</body>
</html>

is there a way to take the above LOCAL file and add javascript so that I can type "Hello World" into the text area, click save and have the file overwrite itself so the file changes to:

<html>
<body>
<form>
    <textarea>Hello World</textarea>
    <input type=submit value="Save"></input>
</form>
</body>
</html>
FatalKeystroke
  • 2,882
  • 7
  • 23
  • 35

2 Answers2

3

In short : no. Plain javascript cannot access the server's file system. If you wish to do that you will need to look at a server scripting or programming environment like PHP, ASP, ASP.NET, etc.

Timothy Groote
  • 8,614
  • 26
  • 52
0

As far as I know this is not possible. You wouldn't want script to be able to access your local filesystem and fiddle with your files, would you. You could do this with Java I think. But that out of scope at this point.

You could write a really simple script in PHP for example, but then you would have to host it on the server or run server on your computer.

What exactly are you trying to achieve? What is the project?

nana
  • 4,426
  • 1
  • 34
  • 48
  • TiddlyWiki does it, so it is possible with the client's local filesystem under certain circumstances. It is not possible however with server documents ;) – Timothy Groote Sep 20 '12 at 17:16
  • Right now I just have to see if it would work, since I can't do it if it doesn't. But I am working on a self contained IRC/custom chat client. If this is possible, the goal would be to write response scripts and simple bots in Javascript within the page itself and be able to save them without a server being present. The key goal is that it's all one file though. – FatalKeystroke Sep 20 '12 at 17:17
  • What about html5 local databases? That should work as long as you host the file from a server, don't think you have access to it from file:// . – nana Sep 20 '12 at 17:19
  • Also, isn't tiddlywiki using Java to achieve that? – nana Sep 20 '12 at 17:21
  • @mistrfu : local databases are called local for a good reason ;) – Timothy Groote Sep 24 '12 at 16:04
  • @TimothyGroote I said host the file. I know the data is stored locally. Imagine you run it from file:///home/you/file.html make changes store to local db, then open file:///home/you/symbolic.link.to.file.html . Will you be able to access the stored data? Does it even store when protocol is file://? I don't know this and haven't looked into it yet, but this is what I meant in my last comment. – nana Sep 24 '12 at 17:28
  • I understand, but there are a myriad of reasons (the same reasons why the original question won't work) on why the local database should not be easily accessible cross-domain. Then again, i never tried. If you do try, please share the outcome, i'd like to know too :) – Timothy Groote Sep 24 '12 at 17:30