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();
}
3
  • 2
    ActiveXObject is Microsoft Specific! Commented Feb 11, 2014 at 6: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). Commented Feb 11, 2014 at 6:41
  • 1
    You can't handle(Write) files from browsers and ActiveXObject is only for IE. Commented Feb 11, 2014 at 6:44

2 Answers 2

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!

Sign up to request clarification or add additional context in comments.

2 Comments

Thank u it work fine in IE but now how can I do the same for all Browser
Thank <deity here> 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: stackoverflow.com/a/20537822/588079
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).

1 Comment

Error: Automation server can't create object

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.