I am learning javascript and so I was trying to append a string to a text file using Javascript. I tried the following but for some reason nothing happens. Where could I be doing wrong ? I am running the code on Mozilla firefox browser.
<%--
Document : demo
Created on : 17 Nov, 2016, 11:01:01 AM
Author : user
--%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h1>Hello World!</h1>
<button onclick="WriteFile()">Click me</button>
<p id="demo"></p>
<script type="text/javascript">
function myFunction() {
document.getElementById("demo").innerHTML = "Hello World";
}
function WriteFile()
{
var fh = fopen("C:\\javascriptlogs\\myfile.txt", 3); // Open the file for writing
if(fh!=-1) // If the file has been successfully opened
{
var str = "Some text goes here...";
fwrite(fh, str); // Write the string to a file
fclose(fh); // Close the file
}
}
</script>
</body>
</html>