Sorry, but it's the same behavior as before.
Edit: I'm hesitant to point to any of my own code, but this worked for me in Safari for loading view files:
function importFile() {
var input = document.createElement('input');
input.type = 'file';
input.onchange = e => {
var file = e.target.files[0];
const reader = new FileReader();
reader.addEventListener(
"load",
() => {
// Do stuff
}
},
false,
);
if (file) {
reader.readAsArrayBuffer(file);
}
}
input.click();
}
One difference I can see is that I'm using the loadend event, whereas you're using the load event. According to the docs, the difference is that loadend is called regardless of whether it was successful or not.
This seems irrelevant though, as my code doesn't appear to be getting as far as the equivalent of your load event hadler. I currently have an event listener on the FileReader for the loadend event, but that is added within the change event listener, the start or which is as follows:
fileInputElem.addEventListener("change", function(event) {
if (this.files.length === 0) {
console.log('No files selected for import');
// No file was selected, so nothing more to do.
resultsHandler.@com.agifans.agile.gwt.GwtOpenFileResultsHandler::onFileResultsReady([Lcom/agifans/agile/gwt/GwtOpenFileResult;)([]);
}
else {
console.log('File(s) were selected for import. Reading them now...');
...and then later on within the code of that 'change' event listener, it creates the FileReader and adds the loadend event handler. But looking at your video, it isn't logging the "File(s) were selected for import. Reading them now..." message, so that would mean that the 'change' event handler hasn't been executed yet, so it wouldn't be getting to the FileReader creation or associated event handler.
But if your code is working in Safari, there must be a clue in there somewhere. Let me look it over for other differences... Hmmm, I can't seem to see anything that would explain why your onchange event handler is running and my one wasn't. I previously had it exactly as you have it, i.e. create the input file element then setting onchange, but that wasn't working, and now also the addEventListener equivalent isn't working.
Maybe there is something different about where our two bits of code are being executed from that makes Safari behave differently.
I can try a couple more things based on other suggestions I've seen in stackoverflow answers. I'll post back here in a bit after making the first of those (probably the appendChild change first, and if that doesn't work, then I'll try changing it to the blur event).
Edit: Just to double check my assumptions above, when you say the following:
Sorry, but it's the same behavior as before.
...were the console log messages also exactly the same? i.e. the "File(s) were selected for import. Reading them now..." message isn't logged? - I just realised I was commenting on the pre "addEventListener" version of the change event handler when referring to the console messages. What I might do before using appendChild is to change the load event of the FileReader to also use addEventListener, since I'm guessing I'll have an issue with that one as well.