IE10 use BLOB url in iframe

IE10 use BLOB url in iframe

本文关键字:in iframe url BLOB use IE10      更新时间:2023-09-26

我正在创建一个BLOB url并将此url分配给iframe的位置。在Firefox和Chrome中,这工作没有问题,在IE10中,BLOB url的内容不显示在iframe中。在IE10调试器中,我可以看到,创建BLOB url没有问题。

var test =
{
   init: function()
   {
      var parts = ["<html><body>test</body></html>"];
      var myBlob = new Blob(parts, {"type":"text'html"}); 
      var blobUrl = URL.createObjectURL(myBlob);
      document.getElementById("test").contentWindow.location = blobUrl;
   }
}
window.addEventListener("DOMContentLoaded", test.init, true);

你知道怎么了吗?

请尝试对每个BlobBuilder和Blob构造函数使用特征检测。

if (typeof Blob !== "undefined") {
   // use the Blob constructor
} else if (window.MSBlobBuilder || window.WebKitBlobBuilder || window.MozBlobBuilder) {
   // use the supported vendor-prefixed BlobBuilder
} else {
   // neither Blob constructor nor BlobBuilder is supported
}
另一个技巧是使用URL.createObjectURL(blob)相对于window:
var blobUrl = window.URL.createObjectURL(myBlob);

IE在这一点上是明智的!也许这有帮助!