1

I have one file i.e style.css/any file whose content need to be shifted to another text file which is file.txt. Using ActiveXObject is not working, so could you please provide any other solution.?

Here is my code which I tried.

jQuery(function ($) {
    $.get('css/style.css', function (data) {
      //  alert(data);
        writeToFile(data);
    });

    function writeToFile(content) {
      //  alert(content);
        var fso = new ActiveXObject("Scripting.FileSystemObject");
        var fh = fso.OpenTextFile("file.txt", 8);
        fh.WriteLine(content);
        fh.Close();

    }
});
mplungjan
  • 169,008
  • 28
  • 173
  • 236
VinK
  • 69
  • 7
  • You have a couple of options, the easiest option would be plain HTML5 and Javascript. https://thiscouldbebetter.wordpress.com/2012/12/18/loading-editing-and-saving-a-text-file-in-html5-using-javascrip/ Also your question sounds very demanding maybe change it a bit – Collin Jun 15 '15 at 12:29
  • 1
    Why? Whatever you are trying to do it sounds like you are doing it wrong. – max Jun 15 '15 at 12:31
  • Please check this http://stackoverflow.com/questions/21012580/is-it-possible-to-write-data-to-file-using-only-javascript – michelem Jun 15 '15 at 12:32
  • I believe this is an [X/Y problem](http://meta.stackexchange.com/questions/66377/what-is-the-xy-problem) - also your ActiveX would likely work in an HTA – mplungjan Jun 15 '15 at 12:38

1 Answers1

1

You can try this window.location = "data:text/html," + yourData

It'll dump the data in the url and force a download of the data.

Seeya
  • 163
  • 2
  • 16