I'm trying to programmatically open a file input from javascript and it's not working in Safari (13.0.5). This file input is not hidden or anything. I've tried all these different ways so far:
<input type="file" id="markupImport"></input>
$('#markupImport').click()
$('#markupImport').trigger('click')
document.getElementById('markupImport').click()
document.getElementById('markupImport').trigger('click')
event = document.createEvent('MouseEvents')
event.initEvent('click', true, false)
$('#markupImport')[0].dispatchEvent(event)
document.getElementById('markupImport').dispatchEvent(event)
event = document.createEvent('MouseEvents')
event.initMouseEvent('click', true, true, window)
$('#markupImport')[0].dispatchEvent(event)
document.getElementById('markupImport').dispatchEvent(event)
document.getElementById('markupImport').dispatchEvent(new Event('click'))
I've looked at In JavaScript can I make a "click" event fire programmatically for a file input element?, calling click event of input doesn't work in Safari, Unable to click input type="file" in windows safari browser, Programmatically trigger "select file" dialog box, and all the others I can find already.
I'm trying to do this from a select
onchange
handler when a certain option is selected:
<select id="markupImport">
<option value="Import">Import</option>
<option value="Export">Export</option>
</select>
<input type="file" id="markupImport"></input>
$(function() {
$('#markupImport').change(function(event) {
if (event.target.value == 'Import') {
$('input[name="markupImport"]').click();
}
});
});
I'm wondering if it's not even possible to do this in Safari anymore.