Hi Html5 developers and HTML4 developers too...
I want to know whether is there any way to support window.fileReader API of html5 in IE8 and above.
the code below :
if(window.fileReader){
alert("supported"); // in html5 works and fires alert but not in IE8
}
Actually, i want to read the contents of file before submitting.
Waiting for the response..
There are multiple pieces that you'll need to check the support of:
//Full File API support.
if ( window.FileReader && window.File && window.FileList && window.Blob )
{
//Supported
}
else alert( "Not supported" );
Your second requirement:
I also want to know the way to read the file contents without using HTML5 fileAPI... but not using ActiveXObject.
What you could do is this:
document.getElementById( "myForm" ).target = "myIframe"; document.getElementById( "myForm" ).submit();
<script>window.parent.someCallbackFunction( theFileCOntents );</script>
)You can check features with simple if logic and wrap your functionality there.
if ('FileReader' in window) {
// Do something with FileReader since it's supported
} else {
// Do something with your polyfill solution
}
You can try a polyfill solutions like this one (works in IE8): https://github.com/Jahdrien/FileReader
You can always use a try-catch to check the FileReader() is supported in a browser.
try {
var reader = new FileReader();
//do something
}
catch(e) {
alert("Error: seems File API is not supported on your browser");
//do something
}
©2020 All rights reserved.