2013-03-06 73 views
2

我使用Firefox擴展的Firebug擴展。從我的擴展中,我必須創建一個報告。我正在嘗試打開一個新窗口並在其中寫入代碼。我可以用下面的代碼打開一個窗口,但無法寫入任何內容到該窗口。我得到一個錯誤「newWindow.document.write()不安全」打開一個窗口並寫入該窗口

如果我使用​​3210我能夠將內容寫入窗口,但我想以其他方式執行,因爲從我的工具生成的文本具有腳本和css它。

這裏是我的代碼片段:

var newWindow = window.open ("","Test","width=335,height=330,resizable=1,toolbar=1,scrollbars=1,status=0") 


newWindow .document.open() 
// html is the data to be shown on the window. It has script and 
// the content in it. 
newWindow .document.write(html) 
newWindow .document.close() 
+0

好了,你有多餘的空間的一兩件事。例如'newWindow .document'應該是'newWindow.document'。 – BenM 2013-03-06 17:06:23

+0

你的答案在這裏:http://stackoverflow.com/questions/10569374/how-to-set-the-innerhtml-of-some-element-in-a-window-opened-by-a-javascript-wind – 2013-03-06 17:07:01

+0

哦,這是一個錯字,而在這裏發佈。我的原始代碼沒有他們... – user1588142 2013-03-06 17:07:38

回答

3

使用這樣的:

<script> 
var w = window.open('', 'wnd'); 

w.document.body.innerHTML = "<b>Hello, stackoverflow!</b>"; 
</script> 
+0

「如果我使用'document.body.innerHTML()'我可以將內容寫入窗口,但我想以其他方式進行,因爲從我的工具生成的文本具有腳本和CSS。」 – BenM 2013-03-06 17:09:40