0

How can I write text files on c:? I can create files on d: but why not on the other? Maybe there's some restriction on that.

Here's my code

openTxt.html

<html><head>
<script language="javascript">

function WriteToFile()
{
var fso = new ActiveXObject("Scripting.FileSystemObject");
var FileObject = fso.OpenTextFile("C:\\LogFile.txt", 8, true,0); // 8=append, true=create if not exist, 0 = ASCII
FileObject.write("hey!")
FileObject.close()
}
</script>
</head>
<body onLoad="WriteToFile()">

</body>
</html>

1 Answer 1

1

In general it is bad practice to access the client Operating System with javascript, and in many cases it is near impossible with some exceptions (like using an ActiveX control).

Typically if you want to write a log file, that is more for server side coding. If you have a server-side platform behind this page, I would use a web service to handle your logging.

Why write logs on the client machine?

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

2 Comments

Yeah, because Im dealing with a widget. More on client part than server side. I think its better to store my tokens in a file, like others do on their widgets, but still I'm open with suggestions right now.
Alright. Have you tried a jscript logging tool like log4javascript: log4javascript.org? A few more are suggested here: ajaxpatterns.org/Javascript_Logging_Frameworks. I would use one of these and save yourself the effort since logging can be so cumbersome.

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.