Reputation: 5598
I have an upload area on my site that when used within IE9-11 the file path has the C:\fakepath\ preface included on the filename. So I built a workaround to remove this but it is only working in FF and Chrome. When used in IE the fields do not update. I believe it is an issue with the setInterval
call but I'm not certain. Below is my code. And here is a Fiddle to show the issue (use in IE to replicate issue): http://jsfiddle.net/daQD6/5/
$(document).ready(function () {
setInterval(running, 1);
function running() {
var filenameIn = $('input[type=file]').val();
var filenameOut = filenameIn.split('\\').pop();
$('#path').text(filenameIn);
$('#result').text(filenameOut);
}
});
Any ideas on a workaround or cause of issue within IE? Many thanks and happy holidays!
Upvotes: 2
Views: 391
Reputation: 15397
Chris Hardie has already answered your IE issue, but I wanted to bring some things to your attention regarding file input.
I've updated your fiddle (and changed the jQuery version as per Chris' suggestion) to use the code from html5rocks, in their Using form input for selecting section.
<input type="file" id="files" name="files[]" multiple />
<output id="list"></output>
function handleFileSelect(evt) {
var files = evt.target.files; // FileList object
// files is a FileList of File objects. List some properties.
var output = [];
for (var i = 0, f; f = files[i]; i++) {
output.push('<li><strong>', escape(f.name), '</strong> (', f.type || 'n/a', ') - ',
f.size, ' bytes, last modified: ',
f.lastModifiedDate ? f.lastModifiedDate.toLocaleDateString() : 'n/a',
'</li>');
}
document.getElementById('list').innerHTML = '<ul>' + output.join('') + '</ul>';
}
document.getElementById('files').addEventListener('change', handleFileSelect, false);
You'll notice, if you make use of the events associated with the file input, you always get the filename without path in evt.target.files[0].name
. If you use the event process, you won't need to setInterval
.
Upvotes: 2
Reputation: 16733
Bug in your version of jQuery (v. 1.10.1): http://bugs.jquery.com/ticket/13980
Use a newer version - v 1.10.2 and higher have the fix.
Upvotes: 4