Small question:
Is it possible to make new file using JavaScript? I'm looking for something like the PHP function fopen and fput. Is this totally impossible? And what about JavaScript function OpenTextFile()?
Small question:
Is it possible to make new file using JavaScript? I'm looking for something like the PHP function fopen and fput. Is this totally impossible? And what about JavaScript function OpenTextFile()?
Only possible with HTML5 apparently.
And here's creating text files:
Here are some resources to get you started.
Writing to a file/directory: http://www.html5rocks.com/en/tutorials/file/filesystem/
Downloading a file: http://html5-demos.appspot.com/static/a.download.html
Downloading a zip: http://stuk.github.com/jszip/
Reading a file: http://www.html5rocks.com/en/tutorials/file/dndfiles/
The top 2 only work in chrome.
jszip has mixed support, and reading files with HTML5 has support in all modern browsers.
It is possible to set the data to a link's href. But a user will have to right click > save link as and add the extension.
<a id="test" target="_blank">click me</a>
document.getElementById('test').href = "data:text/json;charset=utf-8," + escape("Your String goes here");
part extension. but i need to create a .txt file. possible ?In the browser, no. Server-side (as in node.js), yes.
There is no js function to open a text file from the file system, but you can fetch the contents of a text file on your server with an Ajax request.
XMLHttpRequest on local filesystem.