Home javascript javascript Creating files on the client side without server participation

javascript Creating files on the client side without server participation

Author

Date

Category

How with JavaScript, you can implement the creation of files, there is such an HTML structure. The meaning is that when choosing, a text document is created, on the specified path.

& lt; body & gt;
& lt; h2 & gt; File creation path & lt; / h2 & gt;
& lt; Form name = "Form1" & gt;
  & lt; Input Text = "Text" Size = "40" Value = "D: \\ TextFile.txt" name = "Pole" & gt;
  & lt; br & gt;
  & lt; Input Type = "Button" onClick = "F1 (FRM1.Pole.Value)" Value = "Create a file" & gt;
& lt; / form & gt;
& lt; h2 & gt; what create files & lt; / h2 & gt;
& lt; Form name = "Form2" Method = "POST" ACTION = "" & gt;
  & lt; input type = "checkbox" name = "total" value = "checkbox" onClick = "Checkall (this.form, 'checkbox []', this.checked)" & gt; Mark all
  & lt; br & gt;
  & lt; Input Type = "Checkbox" name = "checkbox []" value = "checkbox" & gt; heder
  & lt; br & gt;
  & lt; Input Type = "Checkbox" name = "checkbox []" value = "checkbox" & gt; footer
  & lt; br & gt;
  & lt; Input Type = "Checkbox" name = "checkbox []" value = "checkbox" & gt; sidbar
& lt; / form & gt;


Answer 1, Authority 100%

From pure JavaScript In the browser, you can only download – & nbsp; via the file saving dialog. In addition to those mentioned @ Dmitry-nikitin ways , there is still BLOB Supported by modern browsers, which is preferable to data volumes greater than a few megabytes.

If you need it exclusively locally, and you want to program only on JavaScript – & nbsp; option to put locally node.js He knows how to create local files via FileSystem API , for example (code Syuda ):

var fs = require ('fs');
FS.WRITEFILE ('D: \\ TextFile.txt', "Prevetern", Function (ERR) {
  if (err) {
    RETURN CONSOLE.LOG (ERR);
  }
  Console.log ("File is saved.");
});

Answer 2, Authority 67%

JavaScript is performed in the browser, you can send the file to 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 settings of programs
    default

  2. Attribute download http://caniuse.com/#search=download


Answer 3

JavaScript You will not create a file and nowhere, this is a scripting language with execution on the client side. If you want to create a file on the server, you can use a bundle with PHP

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions