I know that since the creation of HTML5 there has been many additions that make programming websites more easy than ever. It seems they may have failed to add a File system that actually creates a file in a specified directory (not to my knowledge anyway). I have been searching the web and have found nothing about doing such a thing without using a 3rd party i.e JQuery, php, Javascript Libraries. I assume that since there is pure js libraries that can accomplish this that it is possible, but I do not know for sure. What I would like to do is output an html file from the outerHtml generated in my JavaScript minus the script source itself. Note that I do not want the client to have to download.
Asked
Active
Viewed 124 times
0
-
May be this one helps you http://stackoverflow.com/questions/7160720/create-a-file-using-javascript-in-chrome-on-client-side – Manwal Jun 17 '14 at 03:46
2 Answers
1
Try this:
<head>
<script type="text/javascript">
function WriteToFile(passForm) {
set fso = CreateObject("Scripting.FileSystemObject");
set s = fso.CreateTextFile("C:\test.txt", True);
s.writeline("HI");
s.writeline("Bye");
s.writeline("-----------------------------");
s.Close();
}
</script>
</head>
<body>
<p>Fill out the form below:
</p>
<form onSubmit="WriteToFile(this)">
Type your first name:
<input type="text" name="FirstName" size="20">
<br>Type your last name:
<input type="text" name="LastName" size="20">
<br>
<input type="submit" value="submit">
</form>
This will work only on IE.
Also see: create a file using javascript in chrome on client side

Community
- 1
- 1

Chankey Pathak
- 21,187
- 12
- 85
- 133
1
Preventing webpage scripts from creating files on local filesystem is done for your own security. You don't want website you visit create an executable file on your local disk with virus.
There is a File System API in HTML5, but it's kind of internal filesystem intended as a local storage for user data.
You can force user to save file by returning HTTP header Content-Disposition
with value attachment; filename=example.csv
. This will force browser to save file locally.

Maksym Kozlenko
- 10,273
- 2
- 66
- 55