2009-08-18 9 views
0

(XPCOM) innerred되고 싶지 않습니다. 왜 내가 document.body.innerHTML = data; 새로 열린 탭에서 작동하지 않습니다. 여기 내 코드는 다음과 같습니다.구글은 내가 파이어 폭스 확장을 위해 노력하고있어

 
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; 

} 

답변

2

컨텐츠 문서를 변경하려고합니다. 코드가 주어지면 document은 XUL 창 (또는 귀하의 경우 브라우저)을 가리키고 있으므로이를 변경하려고합니다. body이 존재하지 않으므로 액세스 할 때 오류가 발생해야합니다. (Make sure you've enabled chrome errors.) 정말로 원하는 것은 content.document.body.innerHTML입니다.