Show blob in iframe fails in IE

2019-07-17 02:34发布

问题:

So, the gist is, I'm downloading uploaded files to the db to show them, at least most of them, inside a iframe

This is the code:

var ancho = $(window).width() * 0.90;
var alto = $(window).height() * 0.90;
$("#DialogoImagen").dialog({
    show: {
        effect: 'blind'
    },
    hide: {
        effect: 'blind'
    },
    width: ancho,
    height: alto,
    resizable: true,
    draggable: true,
    title: '',
    modal: true,
    position: { my: "center", at: "top", of: window }
});
$("#DialogoImagen").children().remove();
var iframe = $("<iframe width='98%' src='" + window.URL.createObjectURL(archivo) + "'/>");
$("#DialogoImagen").append(iframe);

Its nothing of the other world, I set the iframe src with a window.URL.createObjectURL(blob), works flawlessly with Chrome, FF, Opera, but, IE, even 11, is showing nothing, any idea what to do to solve it?

回答1:

Depends what type of content you're working with, but since it's going in an IFRAME it's a fair bet that IE just doesn't support data URIs for that content type. ref: caniuse

According to the above reference, IE supports images, CSS and script files, but not HTML. I can verify from personal experience that HTML data URLs, e.g.

data:text/html, <h1>Hi</h1><p>I'm a data URL

don't work in IE10.