Click here to Skip to main content
15,899,126 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
As title.
I am maintaining a web page system, and adding some new features on it. I want to write log to a file on server instead of console.log() because I want to know what happened and when, and I think that it may make me tracing bugs easier. But I searched on Google for several solutions, some uses ActiveXObject and some uses Node.js. And I failed to use ActiveXObject on Edge.
How could I make it?

What I have tried:

JavaScript
function WriteLog(eventdata){
    var fs=new ActiveXObject("Scripting.FileSystemObject");
    var f=fs.OpenTextFile("D:\\log.log",2,true);
    f.Write(eventdata+"\r\n");
}

I executed this function on Edge and get an error says "'ActiveXObject' is not defined".
Posted
Updated 14-Feb-19 16:58pm

1 solution

You're not going to be able to write to a file on the server from code running in the browser.

ActiveX isn't supported by any current browsers because it was found to be insecure.

You can use an ajax call to a method the web server exposes to tell it to write something to the log. Goggle for "javascript ajax call" for examples. You're also going to have to write a Web Api method to give the browser something to call.
 
Share this answer
 
Comments
Momoko Asahina 708H 15-Feb-19 1:44am    
OK, I make it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900