0

This code is not working in any Browser

function Submit1_onclick() {
    var fso, f1, ts;
    var ForWriting = 2;
    fso = new ActiveXObject("Scripting.FileSystemObject");
    fso.CreateTextFile("F:/test1.txt");
    f1 = fso.GetFile("F:/test1.txt");
    ts = f1.OpenAsTextStream(ForWriting, true);
    // Write a line with a newline character.
    tf.WriteLine("Testing 1, 2, 3.");
    // Write three newline characters to the file.
    tf.WriteBlankLines(3);
    // Write a line.
    tf.Write("This is a test.");
    tf.Close();
}
Devjosh
  • 6,450
  • 4
  • 39
  • 61
  • 2
    `ActiveXObject` is Microsoft Specific! – silly Feb 11 '14 at 06:40
  • 2
    'any browser' ?? Did you try IE? What is your question? Besides, writing to the local file system is restricted to HTA and trusted (elevated security) 'web-pages' (preferably on intranet). – GitaarLAB Feb 11 '14 at 06:41
  • 1
    You can't handle(Write) files from browsers and ActiveXObject is only for IE. – Amit Garg Feb 11 '14 at 06:44

2 Answers2

1
// Write a line with a newline character.
tf.WriteLine("Testing 1, 2, 3.");
// Write three newline characters to the file.
tf.WriteBlankLines(3);
// Write a line.
tf.Write("This is a test.");
tf.Close();

Change the tf to ts, you had a typo. And run it in IE. I tried it and it works in IE9. You can see your typos in console (Press F12).

GitaarLAB
  • 14,536
  • 11
  • 60
  • 80
xiawenqi
  • 11
  • 3
1

user2965026 already gave the correct answer (typo).

But the asker also has another problem as stated in his comments: Error: Automation server can't create object

If you google this question you'll find what I already stated in my comment to your question: you need to elevate the security rights of the script:

  • Go to inernet options.
  • Select security tab.
  • Under Custom level.
  • Ensure that "Initialize and script active x controls is not marked safe for scripting" is enabled and try to run your code now

Better is to add your site to the trusted domains (and check this option in that section), instead of opening this security hole for all websites!

GitaarLAB
  • 14,536
  • 11
  • 60
  • 80
  • Thank u it work fine in IE but now how can I do the same for all Browser – user3265409 Feb 11 '14 at 07:51
  • Thank you can't (although sadly that's what crippling TiddlyWiki). You can have your users download the file however (even generated/fetched in javascript) and have them (your users) point to the correct location them-selves (or copy the file to there). However (assuming you are sill working on your licence activation app) as I have commented on similar questions: you should add that functionality to your locally (at the user's computer) installed program (or create a separate companion program). Also read this somewhat related Q/A: http://stackoverflow.com/a/20537822/588079 – GitaarLAB Feb 11 '14 at 08:02