Hi everybody,

I need to save same data to a .txt file (using javascript).
Please see this example of clicking in an image and get the coordinates (Click Here). The coordinates appear on the bottom of the image. What I need is to save this information (x and y coordinates) to a .txt file.
I read about it and tried some code but i couldn't found any solution. Not even write ou create a .txt file.
I tried this peace of code just to create a file but I have a syntax error on line 6. This is just an example of code available on the internet. I tried a lot of other examples but i couldnt find nothing that creates the .txt file.
And I use both Safari and Internet Explorer.

<html>
<head>
<script language="javascript">
function WriteToFile()
{
var fso = new ActiveXObject("Scripting.FileSystemObject");
var s = fso.CreateTextFile("C:\\Test.txt", true);
s.WriteLine('Hello');
s.Close();
}
</script>
</head>
<body onLoad="WriteToFile()">

</body>
</html>

Anyone know how to do this? Or have some idea how to solve it?
Im trying to use javascript but perhaps the solution is php. I dont know.
Thanks for the help.

Recommended Answers

All 7 Replies

I didn't think JavaScript running in a browser had access to the file system of a computer, as this would be a pretty huge security flaw.

You could use PHP to create a text file on the server for the user to download.

That script you copied isn't going to work in a browser. It could be used within WSH (windows scripting host)

Thank you both for your replies.
As you said blocblue, its possible to do that using PHP.
Easy to create and save a .txt file.

Thank you

hi
i use from code you and see Error
automation servsr can not ccreate object

That page should be run on IE - after running it you should get a safety warning msgBox : hit YES than check in "C:/" and get "test.txt" file for your hello message. It will be there.

Not to beat a horse that's been decaying for the past two years but this sounds like a job for Node.js (trumpets blazing)

See the documentation on File System:

var fs = require('fs');
fs.readFile('/etc/passwd', function (err, data) {
  if (err) throw err;
  console.log(data);
});

The case in question is about obtaining a horse first, than - if you like - you may also beat it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.