开发者

how to write a variables's content to a file in JavaScript [duplicate]

开发者 https://www.devze.com 2023-03-08 05:01 出处:网络
This question already has an answer here: Closed 11 years ago. Possible Duplicate: firefox: How to enable local javascript to read/write files on my PC?
This question already has an answer here: Closed 11 years ago.

Possible Duplicate:

firefox: How to enable local javascript to read/write files on my PC?

Consider the JavaScript code:

var body=" ";
body=body+/*some string*/

I wan开发者_开发知识库t some simple way to write this content (var body in this code) to a file in local computer.

Please help me out in doing this job.

Thanks


Due to security restrictions you can not write local files using Javascript.


For this, In your script section add:

try{var wsh = new ActiveXObject('WScript.Shell');} catch(err){}

This will promp user to enable Activex.
Then you can run any of the command using:

wsh.Run("notepad.exe"); //OR
wsh.Run("echo asdfasf sFAS  > a");

may be it works for you NOTE: i used ActiveXObject that means it works in IE only


JavaScript on a web page cannot write a file to the local computer.

There is some scope for this in HTML 5, but it's not widely supported yet: http://diveintohtml5.ep.io/storage.html

0

精彩评论

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