-3
I am creating a code editor (Javascript and HTML with iframe
) where I need to save a file .html
dynamically with Javascript. How can I do this?
<HTML> <HEAD>
<SCRIPT language="JavaScript">
function escreverArquivo() {
var fso = new ActiveXObject("Scripting.FileSystemObject");
var fh = fso.CreateTextFile("c:Teste.txt", true);
fh.WriteLine("Coloque todo o conteudo que voce deseja nesse trecho...");
fh.Close();
}
</SCRIPT></HEAD>
<BODY>
<P><SCRIPT language="JavaScript"> escreverArquivo(); </SCRIPT></P>
</BODY></HTML>
I found this code, but it only appears to save .txt
.
Welcome to Stackoverflow. As far as I know, Javascript, running in browser, is not allowed to write files to the hard drive automatically. You can create an HTML file, and download it on the page. I recommend taking a look at this question, which has a great example where the user does it. https://stackoverflow.com/questions/3665115/how-to-create-a-file-in-memory-for-user-to-download-but-not-through-server
– Sveen
The API
ActiveXObject
is obsolete and therefore should not be used. Moreover, as mentioned in the previous comment, JS (in browser) is not allowed to manage the file system.– Luiz Felipe