I have a change event on a file element 'profileSelectedFile' and in Chrome it works fine the first time I select a file (it gets triggered), but if I run it in IE, the change event doesn't get triggered the first time. I have to run it twice before I get a change event to trigger. Is this a bug with IE?
I think IE might have a problem with the element being hidden, Chrome maybe doesn't have that issue.
FYI - I open a modal that shows different upload types (ex. FB, PC, Instagram), if the uploadFromPC button gets clicked I close the modal and open the fileupload window.
$('#profilePictureUpload').on('click', function() {
$('#modalContainer').load(scope.enumControllers.getUploadModal, function(response, status, xhr) {
$('#uploadModal').modal('show');
$('.uploadFromPc').click(function() {
$('#uploadModal').on('hidden.bs.modal', function(e) {
var control = $("#profileSelectedFile");
control.replaceWith(control = control.clone(true));
document.getElementById('profileSelectedFile').click();
$("#profileSelectedFile").change(function() {
// doesn't get triggered in IE on first file upload event, only second upload triggers this event!
});
});
$('#uploadModal').modal('hide');
});
});
});
<input type="file" style="display: none;" id="profileSelectedFile" src="" />
<input type="button" value="Upload a photo" class="btn btn-lg btn-default" id="profilePictureUpload" style="border: 1px solid lightgrey; font-weight: bold">
UPDATE - I tried this code below but it still only triggers the 'someFunction' on the second time I select a file in the fileupload window
var someFunction = function () {
// what you actually want to do
var i = 0;
};
if ($.browser.MSIE) {
// IE suspends timeouts until after the file dialog closes
$input.click(function (event) {
setTimeout(function () {
if ($input.val().length > 0) {
someFunction();
}
}, 0);
});
}
else {
// All other browsers behave
$input.change(someFunction);
}