admin管理员组

文章数量:1336098

We're creating <iframe>s dynamically (e.g. for a rich text editor or a debug window) and injecting html into the src. For years we used a javascript: url as the src similar to this answer until we ran into same-origin-policy issues with multiple independent iframes.

Our current solution is creating an object url for a blob that contains the html:

var iframe = document.createElement('iframe')
  , html = '<h1>it works!</h1>'
  , blob = new Blob([html], {type: 'text/html'})
  , url = URL.createObjectURL(blob);

iframe.src = url;
document.querySelector('body').appendChild(iframe);

We're creating <iframe>s dynamically (e.g. for a rich text editor or a debug window) and injecting html into the src. For years we used a javascript: url as the src similar to this answer until we ran into same-origin-policy issues with multiple independent iframes.

Our current solution is creating an object url for a blob that contains the html:

var iframe = document.createElement('iframe')
  , html = '<h1>it works!</h1>'
  , blob = new Blob([html], {type: 'text/html'})
  , url = URL.createObjectURL(blob);

iframe.src = url;
document.querySelector('body').appendChild(iframe);

This works fine in Chrome and Firefox, but not in IE11 (for browsers where URL or Blob are undefined we fallback to the javascript: solution). IE11 raises SCRIPT5: Access is denied.

Are we misusing the APIs? Is there a special API for IE? A known workaround?

Share Improve this question edited May 23, 2017 at 11:45 CommunityBot 11 silver badge asked Dec 7, 2015 at 12:40 Dominik SchreiberDominik Schreiber 2,7711 gold badge26 silver badges38 bronze badges 1
  • 1 damn your issue is hard to figure out! I've changed the Security settings of my IE11 to the lowest possible config and I've sandboxed the iframe (html5rocks./en/tutorials/security/sandboxed-iframes) still the code snippet didn't work! There is one IE bug that I saw related to this which had no update whatsoever (connect.microsoft./IE/feedback/details/797361/…) Apparently, IE is seeing this as an XSS even though its a Blob URL...i don't think there's anything wrong with the API as Blobs are supported in IE11 – securecodeninja Commented Dec 7, 2015 at 23:43
Add a ment  | 

2 Answers 2

Reset to default 4

Unfortunately IE does not support DATA URI's*with a few caveats. I have the same issue, but with a PDF in an embedded tag.

It looks like you can use msSaveOrOpenblob to have IE open your blob file

IE 11 does not support all the Data URI's.

It supports only images and linked resources like CSS or JS. Please note HTML files are not supported.

本文标签: javascriptUsing Blob urls for src in IE11Stack Overflow