我正在使用签名的JAR文件将代码转换为使用基于XULRunner的应用程序。我在使用存储在javascript变量中的html内容加载iframe的代码时遇到了问题。
代码如下所示:
var doc = iframe.contentDocument;
doc.open();
doc.write(html);
doc.close();
iframe的type =“content”。就像在XULRunner中一样,我在doc.open()调用中得到一个异常:
[Exception... "The operation is insecure."
code: "18"
nsresult: "0x80530012 (SecurityError)"
location: "chrome://ec4main/content/apps/newsfeedtest/lib.js Line: 938"]
如果我将iframe更改为type =“chrome”,那么它可以正常工作,但这似乎是一个坏主意,因为HTML并不总是受信任的内容。
答案 0 :(得分:4)
您应该使用data URLs代替document.write()
(这确实不安全且不值得推荐):
var wnd = iframe.contentWindow;
wnd.location.href = "data:text/html;charset=utf-8," + encodeURIComponent(html);