Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
340 views
in Technique[技术] by (71.8m points)

activex - Use JavaScript to write to text file?

I have a need to capture the topics of a search from one of my blog pages and write it to text file for followup. I have been able to capture the input string, however, am not able to write it to a text file. I have read and tried to implement all the solutions I have found with no success. I include a very simple sample of code to write text to file but I can't get it to work. The Onblur event functions fine to access myFunction, so that's not problem. I'm going crazy as samples shown from others are so simple.

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" >
    <html xmlns="http://www.w3.org/1999/xhtml">

    <head>
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
    <title>fs=Server CreateObject ("Scripting FileSystemObject")</title>
    <script type="text/javascript">
    function myFunction()
    {
        var fs = ActiveXObject("Scripting.FileSystemObject");
        var f = fs.OpenTextFile("d:\test\topics.txt", 8, true);
        f.WriteLine("This text will be added to the end of file");
        f.Close();
    }
    </script>
    </head>

    <body>
    <input name="Text1" type="text" size="55" onblur="myFunction()" />

    </body>

    </html>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

If your're using modern browsers which support data-uri, you can create content with javascript and force a download by base64 encoding it and making it compatible with data-uri, then simply pointing window location at it.

This answer demonstrates an HTML-only way to do it.

You can also use a flash helper to take care of this. For instance, Downloadify does this.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...