How with the help of javascript it is possible to realize the creation of files, there is such an html structure. The point is that when you select, a text document is created along the specified path.

<body> <H2>Путь создания файлов</H2> <form name="form1"> <input text="text" size="40" value="D:\\textfile.txt" name="pole"> <br> <INPUT TYPE="BUTTON" ONCLICK="f1(frm1.pole.value)" VALUE="Создать файл"> </form> <H2>Какие создать файлы</H2> <form name="form2" method="post" action=""> <input type="checkbox" name="total" value="checkbox" onClick="checkAll(this.form,'checkbox[]',this.checked)">Отметить все <br> <input type="checkbox" name="checkbox[]" value="checkbox">Heder <br> <input type="checkbox" name="checkbox[]" value="checkbox">Footer <br> <input type="checkbox" name="checkbox[]" value="checkbox">SidBar </form> 

  • four
    Possible duplicate question: Create file using javascript - Denis Fedichkin
  • one
    @DenisFedichkin, but is there really an accepted answer? - Visman
  • Yes, I watched it, but decided to ask it again because I stumbled upon this it.kgsu.ru/JS/js0062.html - Stasinskii
  • @DenisFedichkin, not a duplicate - they want a file on the server, and here they want it on the client. - Qwertiy
  • @Qwertiy, there was also a wish on the client - Denis Fedichkin

3 answers 3

You can only download a file from pure JavaScript in the browser through the File Save dialog. In addition to the methods mentioned by @Dmitry-Nikitin, there is also Blob supported by modern browsers, which is preferable for data volumes exceeding several megabytes.

If you need it exclusively locally, and you only want to program in JavaScript - the option is to install Node.js locally - it can create local files via the Filesystem API , for example (code from here ):

 var fs = require('fs'); fs.writeFile('D:\\textfile.txt', "Превед", function(err) { if(err) { return console.log(err); } console.log("Файл сохранён."); }); 
  • ohh thank you, I think it will be a good decision, because Node.js is already worth it - Stasinskii

JavaScript runs in the browser, you can send the file for download in two ways:

  1. base64-encoded content, for example: window.location.href = 'data:application/octet-stream;base64,...'

    Which will be processed by the browser in accordance with the default program settings

  2. Download attribute http://caniuse.com/#search=download

  • Then if I have 10 files on the creation, will I download them all? I need to not see it, everything is quietly created .... - Stasinskii
  • Malware would be very happy about this opportunity. - Sergiks
  • @Sergiks seems to me that he is the same malware - Serge Esmanovich

In JavaScript you can not create a file anywhere, it is a scripting language with execution on the client side. If you want to create a file on the server, you can use a bunch with PHP

  • and is that without server worked? I ran into this article it.kgsu.ru/JS/js0062.html but something does not work. - Stasinskii
  • @Stasinskii where do you want to create a file? - korytoff
  • Locally on the computer but without server participation. I want to facilitate the routine work. - Stasinskii
  • There is hardly any local on the computer, maybe there is some kind of plugin for some kind of browser, but in general it violates the security rules, use other tools and YaP for this purpose
  • It turns out this is only full-fledged languages, such as java .... otherwise it is impossible. - Stasinskii