0

I've made an empty mynote.txt in the same directory,
and open the following code with Internet Explorer,
and allow to write on hard disk (when IE asked)
but nothing in the text file: mynote.txt after the run.
what is the problem?

<html>
<body>
       
<script type="text/javascript">
       
function WriteFile()
{
  var fh = fopen("\\mynote.txt", 3);
    
  if(fh!=-1)
  {
    var str = "Some text goes here...";
    fwrite(fh, str);
    fclose(fh);
  }
}

WriteFile();

</script>

</body>
</html>
2
Contributors
5
Replies
10
Views
6 Years
Discussion Span
Last Post by scrappedcola
0

As far as I know you can't write to a file in this method from within a web page. You need to create an ActiveXObject File System Object in order to access the local file system. This will also only be available in IE as other browsers don't allow access to the FS via web code (rightfully imho) due to security concerns.

function WriteFile()
{
  var fso = new ActiveXObject("Scripting.FileSystemObject");
  var ots=fso.OpenTextFile("c:\\mynote.txt",2,true);
  
  var str = "Some text goes here...";
  ots.Write(str);
  ots.Close();
  ots=null;
  fso=null;
}
WriteFile();
0

I used IE for opening the javascript, as I mentioned.

0

I dont know. Wht is it? And how can I check? Its a software?

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.