1

Is it possible, without a server nor connection to internet, to create an html file, run it in Firefox, and have a form in the html file? You fill it up, and then submit. Upon clicking the submit button, I want to save the text from the form into my PC in the form of a text file or whatever.

chembrad
  • 887
  • 3
  • 19
  • 33
Saturn
  • 17,888
  • 49
  • 145
  • 271
  • 1
    in some way, see this SO thread: http://stackoverflow.com/questions/2004832/write-to-a-textfile-using-javascript and this one: http://stackoverflow.com/questions/2840252/writing-utf8-text-to-file – JMax Oct 08 '11 at 17:50
  • Not easily. This isn't the sort of thing a browser is meant to do. @JMax, those answers are IE-only. – Matt Ball Oct 08 '11 at 17:52
  • Do note that (unless you don't mind), has extreme security implications (an attacker could modify the DOM to save malware into the user's computer), which is why it is disabled in most browsers. Just so you know. – Madara's Ghost Oct 08 '11 at 18:10

6 Answers6

2

As TiddlyWiki demonstrates this is possible in most browsers to save something to your harddrive making use of an applet that is called from a HTML page.

TiddlyWiki is a simple Wiki that can be opened from a single HTML file in your browser without the need of being served through a webserver. Once you have made changes to your Wiki pages you can save them with the help of an applet that is called from the HTML page.

stefanglase
  • 10,296
  • 4
  • 32
  • 42
1

You can do that, but you will need to install an HTTP server such as Apache on your local PC. It doesn't require an internet connection.

Matt Ball
  • 354,903
  • 100
  • 647
  • 710
Dabbler
  • 9,733
  • 5
  • 41
  • 64
1

Why don't you just set up a lightweight web server for testing purposes? The task isn't that difficult and when you do it once you have it available for your testing and you have the skills to do it if you ever need to set one up again.

This previous question could steer you in that direction:

https://stackoverflow.com/questions/595466/is-there-a-lightweight-portable-windows-web-server

Community
  • 1
  • 1
chembrad
  • 887
  • 3
  • 19
  • 33
0

With Flash (FlashPlayer 10+) you can save but also load local files from your harddisk very easy (and no serverside code required). With Actionscript 3 you should use this:

var myText:String = "hello, this is a test";

var file:FileReference = new FileReference();
file.save(myText, "testfile.txt");

This will display the save dialog. If you save the file on your harddisk and then open it with Notepad for example, you'll see the text is inside the file.

More info: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/FileReference.html

Mark Knol
  • 9,663
  • 3
  • 29
  • 44
0

Yes, you can do this but it will require a browser plugin like Flash.

Take a look at Downloadify. It's a JavaScript library that leans on Flash to create a file on the client side and present the file download dialog.

David Walsh has some good demos and info too on his blog, including an example of exactly what you want to do with the form.

nikmd23
  • 9,095
  • 4
  • 42
  • 57
0

With HTML Application (HTA), you can build a whole program with just HTML & JavaScript. And it runs like any other program. The documentations about HTA go here: MS HTA


In order to write a file to hard disk only, you just need these code :

<input id="myInput">
<input type="button" value="Save" onClick="SaveFile()">

<script>
    function SaveFile(){
        var content = document.getElementById('myInput')

        var fso = new ActiveXObject("Scripting.FileSystemObject");
        var a = fso.CreateTextFile("c:\\testfile.txt", true);
        a.WriteLine(content);
        a.Close();
    }
</script>

Save the code in a file with the extension to be ".HTA", ie : "myApp.HTA". Double click it, then enjoy the magic.

You can learn more about HTA in the link above to improve your application. Good luck.

vantrung -cuncon
  • 10,207
  • 5
  • 47
  • 62