开发者

Can javascript be used to write to a file?

Can javascript be used to wri开发者_StackOverflow社区te to a file ? Sorry restate that (Can javascript be used to write to a file on the web server it is hosted on? ).


They used to call cookies "really small files on your computer", so I say: "Yes, yes it can."

update based on edit

Yes, you have to use AJAX to call a web service on the web server.


It can if the "file" is a cookie. I will leave research on that up to the reader.


Not cross-compatibly, unless you do certain trickery. A trusted applet, for example, has complete access to the user's file system, and it can expose javascript methods. Expose a write method in a trusted applet, and you're good to go.


No. if you need to store data on the client, you can use cookies, Google Gears, or the client-side storage supported by modern browsers like firefox and safari.

The YUI Storage Utility is a nice cross-browser wrapper around these methods.


On it's own, no.. at least without exploiting browser / plugin vulnerabilities.

Since you clarified your question:

It can be used to do an ajax call to a server-side script which would then write a file into the file system.


You could make an Ajax call to a web service which would either save the file for you on the server or perhaps serve it back to the browser for download

using jQuery


$.ajax({
   type: "POST",
   url: "save.php",
   data: "name=Bob&Age=1",
   success: function(msg){
     alert( "Data Saved: " + msg );
   }
 });


Unless used in server-side contexts: no, sorry.


Javascript cannot directly write to a file on the webserver on which it is hosted. If it is required, you can use something like an XMLHttpRequest object to communicate your means to a serverside script (like PHP or Python), which will then do the write.

Javascript code is executed on the client side. It does not directly have access to your server.


It depends on a platform. Some platforms (like Windows), allow javascript to access filesystem (in Windows - via FileSystemObject ActiveX object). But client's browser security settings must be adjusted to allow this.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜