Hi, I'm trying to make an firefox extension. Why when I want to use document.body.innerHTML = data; in new opened tab, it doesn't work. Here is my code:
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; }