create a text file using javascript

前端 未结 4 932
走了就别回头了
走了就别回头了 2020-12-03 08:48

I am using the following code to create a text file using javascript and it\'s not working


    
        

        
相关标签:
4条回答
  • 2020-12-03 09:00

    Try this:

    <SCRIPT LANGUAGE="JavaScript">
     function WriteToFile(passForm) {
    
        set fso = CreateObject("Scripting.FileSystemObject");  
        set s = fso.CreateTextFile("C:\test.txt", True);
        s.writeline("HI");
        s.writeline("Bye");
        s.writeline("-----------------------------");
        s.Close();
     }
      </SCRIPT>
    
    </head>
    
    <body>
    <p>To sign up for the Excel workshop please fill out the form below:
    </p>
    <form onSubmit="WriteToFile(this)">
    Type your first name:
    <input type="text" name="FirstName" size="20">
    <br>Type your last name:
    <input type="text" name="LastName" size="20">
    <br>
    <input type="submit" value="submit">
    </form> 
    

    This will work only on IE

    0 讨论(0)
  • 2020-12-03 09:09

    You have to specify the folder where you are saving it and it has to exist, in other case it will throw an error.

    var s = txt.CreateTextFile("c:\\11.txt", true);
    
    0 讨论(0)
  • 2020-12-03 09:14

    That works better with this :

    var fso = new ActiveXObject("Scripting.FileSystemObject");
    var a = fso.CreateTextFile("c:\\testfile.txt", true);
    a.WriteLine("This is a test.");
    a.Close();
    

    http://msdn.microsoft.com/en-us/library/5t9b5c0c(v=vs.84).aspx

    0 讨论(0)
  • 2020-12-03 09:14

    From a web page this cannot work since IE restricts the use of that object.

    0 讨论(0)
提交回复
热议问题