how can i append data to a file using javascript?
i tried to use this code, but i got an error:
var fso = new ActiveXObject("Scripting.FileSystemOject");
var filepath = fso.GetFile("member.txt");
var fileObject = fso.OpenTextFile(filepath, 8);
file.WriteLine(id + "|" + pass);
fileObject.close();
the error is on var fso = new ActiveXObject("Scripting.FileSystemOject");
, written: Error: Automation server can't create object
is there any other way to append the file using javascript or the way to fix this? thanks :)
EDIT: i have doing what's written on this, and it still not working :/
how can i append data to a file using javascript?
i tried to use this code, but i got an error:
var fso = new ActiveXObject("Scripting.FileSystemOject");
var filepath = fso.GetFile("member.txt");
var fileObject = fso.OpenTextFile(filepath, 8);
file.WriteLine(id + "|" + pass);
fileObject.close();
the error is on var fso = new ActiveXObject("Scripting.FileSystemOject");
, written: Error: Automation server can't create object
is there any other way to append the file using javascript or the way to fix this? thanks :)
EDIT: i have doing what's written on this, and it still not working :/
Share Improve this question edited Apr 17, 2012 at 15:14 aquatorrent asked Apr 17, 2012 at 14:49 aquatorrentaquatorrent 8412 gold badges8 silver badges11 bronze badges 7-
Make sure you have
scrrun.dll
installed and registered into your OS. A quicktest: write to mandline:scrrun.dll
. If you'll get aWINDOWS
error, the dll exists, if error text occurs only in manline, there is notscrrun.dll
installed/registered. You can also try to find the file fromsystem32
-folder – Teemu Commented Apr 17, 2012 at 16:28 - i've run it and it gives me a warning that i wanted to open the file :/ – aquatorrent Commented Apr 17, 2012 at 16:31
- Well, the installation seems to be OK then... And you've switched all the necessary settings to "insecure" mode? – Teemu Commented Apr 17, 2012 at 16:38
- how can i switch it to insecure mode? – aquatorrent Commented Apr 17, 2012 at 16:39
- 1 I just realized after wasting an hour, the OP misspelled "Scripting.FileSystemOject", there's 'b' missing in object. That's why it's giving out that error (even if you apply the fix.) Don't copy it into your code :) – c00000fd Commented May 4, 2014 at 22:58
4 Answers
Reset to default 1I just realized these in your code:
var fileObject = fso.OpenTextFile(filepath, 8,true);
You'll need the true
-argument, if the file does not exist, or you want to overwrite/append it.
var filepath = fso.GetFile("member.txt");// This won't work.
var filepath = "your_filePath"; // Use this instead
var fileObject = fso.OpenTextFile(filepath, 8, true);
OpenTextFile()
needs a path as a string like "D:/test/file.txt"
. GetFile()
returns an object, which you can see as a string (D:\test\file.txt
), but it's not a string. Use also absolute paths, relative paths don't seem to work by my experience.
EDIT
Add the code below to the <head>
-part of your html-file, then save locally as a hta (with file extension hta
, not htm
or html
).
<hta:application
applicationName="MyApp"
id="myapp"
singleInstance="yes"
/>
Then run the hta-file. If you still getting an ActiveX-error, it's not supported by your OS. If this works, you haven't done all the security settings correct.
EDIT II
In this case it's not very usefull to get the path through ActiveX, you'll need to write it literal anyway. And I'm not supposed to do your homeworks, but this does the trick...
var filepath = new String(fso.GetFile("member.txt")).replace(/\\/g,'/');
And don't forget what I've said above about using absolute paths...
The 8
in the OpenTextFile
function specify that you want to append to the file. Your problem es from the security restriction of your browser. To make it work you'll have to lower the security level, which is not really remended.
The error is thrown because there are security restrictions which donot allow the activex to run. change your security settings to allow the activex if your using internet explorer (which i think you are). This might be useful http://windows.microsoft./en-US/windows/help/genuine/ie-activex Cheers
EDIT: i have doing what's written on this, and it still not working :/ * try Restarting your browser
As pointed out in this ment
Javascript: how to append data to a file
the cause of the error Error: Automation server can't create object
is the typo in the progid passed to ActiveXObject
: Oject instead of Object:
var fso = new ActiveXObject("Scripting.FileSystemOject");
there is a missing b
!
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745395405a4625854.html
评论列表(0条)