loading an iframe from a string variable in xulrunner
Asked Answered
F

1

1

I am converting code from using signed JAR files to using an XULRunner based applications. I am having trouble with code that loads an iframe with html content stored in a javascript variable.

The code looks like this:

var doc = iframe.contentDocument;
doc.open();
doc.write(html);
doc.close();

The iframe has type="content". As is, in XULRunner I get an exception in the doc.open() call:

[Exception... "The operation is insecure."
   code: "18"
   nsresult: "0x80530012 (SecurityError)"
   location: "chrome://ec4main/content/apps/newsfeedtest/lib.js Line: 938"]

If I change the iframe to type="chrome", then it works but this seems like a bad idea because the HTML is not always trusted content.

Fishplate answered 15/10, 2012 at 15:8 Comment(0)
W
4

You should use data URLs instead of document.write() (which is indeed insecure and not recommendable):

var wnd = iframe.contentWindow;
wnd.location.href = "data:text/html;charset=utf-8," + encodeURIComponent(html);
Winkle answered 16/10, 2012 at 9:10 Comment(1)
+1 for changing document location to data:text/html For information, the message "Exception: The operation is insecure" is a bug on Firefox default console (bugzilla.mozilla.org/show_bug.cgi?id=663406), document.write should work and it works with Firebug console on Firefox and Chromium default console. In my case, if a web page don't load but you can view page source code, I can force HTML display: document.write(document.body.innerHTML) or document.location = "data:text/html;charset=utf-8," + encodeURIComponent(document.body.innerHTML)Stempson

© 2022 - 2024 — McMap. All rights reserved.