Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Local JavaScript - write to local file

I have some JavaScript code loaded from a local HTML file (without going through a webserver).. i.e., opened using file://

Is there a way the JavaScript code in this file can be used to write to a local file?

I know that cross-site restrictions do not allow lot of things in JavaScript, but this is not cross-site, so it should be allowed in theory.

like image 328
Jus12 Avatar asked Mar 18 '11 09:03

Jus12


2 Answers

There's a jQuery plugin jQuery.twFile that allows you to read and write to a local file.

like image 179
Diogo Cardoso Avatar answered Sep 24 '22 00:09

Diogo Cardoso


In case of Internet Explorer you can use ActiveX.

<html>
    <head>
        <script type="text/javaScript">
            function WriteToFile()
            {
               var fso  = new ActiveXObject("Scripting.FileSystemObject");
               var txtFile = fso.CreateTextFile("c:\\TestFile.txt", true);
               txtFile.WriteLine("This is a test");
               txtFile.Close();
            }
        </script>
    </head>

    <body>
        <p>
            <script type="text/javaScript">  WriteToFile(); </script>
        </p>
    </body>
</html>
like image 29
Ashwin Krishnamurthy Avatar answered Sep 23 '22 00:09

Ashwin Krishnamurthy