2013-03-06 147 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