HTML saving some text in my PC?
Is it possible, without a server nor connection to internet, to create an html file, run it in Firefox, and h开发者_开发问答ave 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.
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.
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.
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
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
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.
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.
精彩评论