Reputation: 21285
Following code works fine in Chrome, but fails in IE9 - in processFiles()
when we retrieve selected files e.target.files
is null
<!DOCTYPE html>
<html>
<header>
<meta http-equiv="X-UA-Compatible" content="IE=8" />
</header>
<body>
<input type="file" id="uploader"/>
<script>
var uploader = document.getElementById ("uploader");
if (uploader.addEventListener) { // all browsers except IE before version 9
uploader.addEventListener ("change", processFiles, false);
}
else {
if (uploader.attachEvent) { // IE before version 9
uploader.attachEvent ("change", processFiles);
}
}
function processFiles(e)
{
var files = e.target.files || e.dataTransfer.files;
for (var i = 0 ; i < files.length ; i ++)
{
window.console && console.log && console.log(files[i].name);
}
}
</script>
<body>
Any ideas?
Upvotes: 3
Views: 7213
Reputation: 19890
Your code assumes support for the File API. The first version of IE to support the File API is IE10. Your code will never work cross-browser as it stands now.
Consider using Fine Uploader which already handles uploads cross-browser and includes a number of useful features.
Upvotes: 2