[英]How to get Cross Browser Compatibilty for window.fileReader API of HTML5
嗨Html5開發人員和HTML4開發人員......
我想知道是否有任何方法支持IE8及以上版本的html5的window.fileReader API。
代碼如下:
if(window.fileReader){
alert("supported"); // in html5 works and fires alert but not in IE8
}
實際上,我想在提交之前閱讀文件的內容。
等待回復..
您需要檢查以下內容的多個部分:
//Full File API support.
if ( window.FileReader && window.File && window.FileList && window.Blob )
{
//Supported
}
else alert( "Not supported" );
你的第二個要求:
我也想知道在不使用HTML5 fileAPI但不使用ActiveXObject的情況下讀取文件內容的方法。
你能做的是:
document.getElementById( "myForm" ).target = "myIframe"; document.getElementById( "myForm" ).submit();
<script>window.parent.someCallbackFunction( theFileCOntents );</script>
) 您可以使用簡單的if邏輯檢查功能並將功能包裝在那里。
if ('FileReader' in window) {
// Do something with FileReader since it's supported
} else {
// Do something with your polyfill solution
}
您可以嘗試像這樣的polyfill解決方案(適用於IE8): https : //github.com/Jahdrien/FileReader
您始終可以使用try-catch檢查瀏覽器是否支持FileReader()。
try {
var reader = new FileReader();
//do something
}
catch(e) {
alert("Error: seems File API is not supported on your browser");
//do something
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.