Google no quiere ser innerred (XPCOM)
-
18-09-2019 - |
Pregunta
Estoy tratando de hacer una extensión de Firefox. ¿Por qué cuando quiero usar document.body.innerHTML = datos; en una nueva pestaña abierta, que no funciona. Aquí está mi código:
function change() { //Open google in new Tab and select it tab=gBrowser.addTab("http://www.google.com"); gBrowser.selectedTab=tab; //Create nslFile object var path="/home/foo/notify.txt" var file = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile); file.initWithPath(path); //Put file content into data variable var data = ""; var fstream = Components.classes["@mozilla.org/network/file-input-stream;1"]. createInstance(Components.interfaces.nsIFileInputStream); var cstream = Components.classes["@mozilla.org/intl/converter-input-stream;1"]. createInstance(Components.interfaces.nsIConverterInputStream); fstream.init(file, -1, 0, 0); cstream.init(fstream, "UTF-8", 0, 0); // you can use another encoding here if you wish let (str = {}) { cstream.readString(-1, str); // read the whole file and put it in str.value data = str.value; } cstream.close(); // this closes fstream //change content of google page by file content document.body.innerHTML = data; }
Solución
Usted está tratando de cambiar el documento de contenido, ¿verdad? Dada su código, puntos document
a la ventana XUL (o el navegador en su caso), por lo que usted está tratando de cambiar eso. Que debería estar recibiendo un error sobre el acceso a body
en él desde que no existirá. ( Asegúrese de que los errores de cromo que ha habilitado .) Lo que realmente quiere es content.document.body.innerHTML
.
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow