MozillaES.org
«La comunidad de Mozilla en español»

Escribir archivo txt desde uerscript de GreaceMonkey

Publicar una respuesta


This question is a means of preventing automated form submissions by spambots.
Emoticonos
:-) ;) :rolls eyes: :-/ :-( =-O :-D :-* :-P :-[ :-! 8-) :bitchin:
Ver más emoticonos
BBCode está habilitado
[img] está habilitado
[flash] está deshabilitado
[url] está habilitado
Emoticonos están habilitados
Revisión de tema
   

Expandir vista Revisión de tema: Escribir archivo txt desde uerscript de GreaceMonkey

Escribir archivo txt desde uerscript de GreaceMonkey

Nota por FDamn » Mar Feb 14, 2012 6:18 am

Hola! Esto es bastante especifico, ojala puedan ayudarme..
El siguiente codigo, asi como está, funciona:

<html>
<head>
<script>

// IO.JS - file input/output for Firefox
// ...And every bit of it ripped from MDC's examples. Seriously though, I don't think they could have made it any more complicated. :P

this.netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');

function writeFile (fileData, filePath)
{
// "fileData" is a string containing the data to write. "filePath" is a string containing the complete path for the file.
// This function writes a string to a file, erasing its previous content.
var file = Components.classes["@mozilla.org/file/local;1"]
.createInstance(Components.interfaces.nsILocalFile);
file.initWithPath( filePath );
file.createUnique( Components.interfaces.nsIFile.NORMAL_FILE_TYPE, 600);
var stream = Components.classes["@mozilla.org/network/safe-file-output-stream;1"]
.createInstance(Components.interfaces.nsIFileOutputStream);
stream.init(file, 0x04 | 0x08 | 0x20, 0600, 0); // readwrite, create, truncate
stream.write(fileData, fileData.length);
if (stream instanceof Components.interfaces.nsISafeOutputStream) {
stream.finish();
} else {
stream.close();
}
}
//********************************************************************************
writeFile("soy un archivo escrito desde javascript!!","C:\\file.txt"); //archivo a crear
//********************************************************************************
</script>
</head>
<textarea></textarea>
<input>
<input>
</html>


Si lo copian y luego lo pegan en un archivo.html y lo abren con firefox, se creara el archivo "C:\file.txt".
Ahora, exactamente el mismo codigo (solo el script, sin los tags <html> y <head>), lo agrego a una pagina web a traves de un userscript de GreaceMonkey y acusa el error:
"El uso de enablePrivilege está desaprobado. Por favor, use en su lugar código que se ejecute con el principal del sistema (p.e. una extensión)."

¿Alguna idea de como resolver esto? (ya entre a about:config y puse true en signed.applets.codebase_principal_support)
Muchas Gracias!

Arriba