2013-01-03 45 views
0

我正在創建BLOB網址並將此網址分配給iframe的位置。在Firefox和Chrome中,這沒有問題,在IE10中,BLOB網址的內容不會顯示在iframe中。在IE10調試器中,我可以看到BLOB網址創建時沒有問題。IE10在iframe中使用BLOB網址

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); 

任何想法有什麼不對?

回答

0

請嘗試使用每個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是關於這個明智!也許這有幫助!

+0

Blob構造函數存在,BlobUrl已成功創建。不幸的是使用window.URL.createObjectURL沒有幫助。 – meagain

+0

並追蹤出特徵檢測的錯誤您收到了什麼類型的消息? –

+0

對不起,我不明白你的問題。 「Blob」存在,所以它在第一個「if」之後執行代碼,不會發生錯誤。 – meagain