打开一个窗口并向该窗口写入内容

Open a window and write to that window

本文关键字:窗口 一个      更新时间:2023-09-26

我在Firebug扩展上工作,这是Firefox扩展。从我的扩展,我必须创建一个报告。我正试图打开一个新窗口并将代码写入其中。我能够打开一个窗口与下面的代码,但不能写任何东西到该窗口。我得到一个错误" newWindow.document.write()不安全"

如果我使用document.body.innerHTML(),我能够将内容写入窗口,但我想以其他方式做到这一点,因为从我的工具生成的文本有脚本和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()

使用如下:

<script>
var w = window.open('', 'wnd');
w.document.body.innerHTML = "<b>Hello, stackoverflow!</b>";
</script>