I'm working on porting some js code that works correctly in Chrome to Firefox. I have a following function for reading files from a file system:
function chooseFilesToOpen() {
var fileInput = document.createElement('input');
fileInput.type = 'file';
fileInput.multiple = true;
fileInput.addEventListener('change', function() {
openFiles(fileInput.files);
});
fileInput.click();
}
The function is bound to a button on a page ($('#open-button').click(chooseFilesToOpen)
) and to Ctrl+O shortcut (there's a switch statement for different keys). The function is invoked in both cases, upon Ctrl+O and a button click, but a file browsing dialog appears only in the latter. When I debug it, the dialog pops up when fileInput.click()
is executed. The same statement seems to do nothing when the function is called from a keypress
event handler. So, the question is how to make it work for both actions and in both browsers?