0

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.

6
Contributors
7
Replies
25
Views
4 Years
Discussion Span
Last Post by Troy III
0

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.

0

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

0

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

0

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

0

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.

Edited by Troy III

0

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);
});
0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.