使用javascript创建文本文件

问题描述:

朋友们,我是这个博客的新手,我将使用javascript创建类似文本编辑器的应用程序,我试图通过单击按钮使用ActiveXObject窗口方法创建一个新的文本文件。它创建了一个文件,但我想在我点击按钮时创建一个新的文本文件..

这里我用来创建文件的代码..

function createfile()

{

var file;

var fso = new ActiveXObject(Scripting.FileSystemObject);

var s = fso.OpenTextFile(C:\ Library \ Document \ NewFile.txt,8,true,0);

s.WriteLine(......);

s.Close();

}

请帮帮我...

hi friends i am new to this blog, I am going to creating application like text editor using javascript, I am trying to create a new text file using ActiveXObject window method by clicking the button. Its creating a file but i want to create a new textfile when i clicked the button..
here the code which i used for creating file..
function createfile()
{
var file;
var fso = new ActiveXObject("Scripting.FileSystemObject");
var s = fso.OpenTextFile("C:\Libraries\Documents\NewFile.txt", 8, true, 0);
s.WriteLine(......);
s.Close();
}
please help me...

首先,在JavaScript中使用ActiveX对象是一件非常糟糕的事情,几乎在所有情况下都是如此。所有浏览器和平台都不会支持这一点,更重要的是,它完全不安全。如果任何有经验的用户会发现您正在做这样的事情,那么此类人员将永远不会使用您公司的产品或产品,因为这表明该公司不会考虑非常基本的安全措施。



你真的永远不需要它为你的目的。至于文本编辑器的创建,它们可以是适用于所有平台的纯JavaScrip工具。例如,看看这个HTML(不仅仅是文本)WYSIWYG编辑器:

http://en.wikipedia .org / wiki / TinyMCE [ ^ ],

http://www.tinymce.com/ [ ^ ]。



您可以查看源代码并获取基本想法。



-SA
First of all, it's a really bad thing to use ActiveX object in JavaScript, virtually in all cases. This won't ever be supported by all browsers and platforms, and, more importantly, is utterly unsafe. If any experienced user will see that you are doing such things, such person will never use your products or products of your company, as it would suggest that such company does not consider very basic security practices.

And you really never need it for your purpose. As to the creation of the text editors, they can be pure JavaScrip tools working on all platforms. For example, look at this HTML (not just text) WYSIWYG editor:
http://en.wikipedia.org/wiki/TinyMCE[^],
http://www.tinymce.com/[^].

You can look at the source code and get the basic ideas.

—SA