I am making a site where you can convert your file to a data URL. Here is my current code where you select the file:
function convertToDataURL() {
alert("convert to data url");
}
.dropzone {
border: 1px solid lightgray;
padding: 2rem;
margin: 2rem;
border-radius: 10px;
font-family: Arial;
font-size: 0.8rem;
cursor: pointer;
text-align: center;
}
<input id="fileInput" type="file" style="display: none" onchange="convertToDataURL()" />
<label for="fileInput">
<div class="dropzone">Select or drop a file here</div>
</label>
The JavaScript works just fine, which is why I left it out. If I click the file input and select a file, the conversion successfully works. But if I drag a file to the file input, the input doesn't register the file, and the file just opens in a new tab. What is the cause of this, and how can I fix it?
<div>with no backing JavaScript functionality would accept a file drop out of the box? Can you share the source upon which you're basing that implicit claim? Usually you need to include something likedropzone.jsto get the functionality you need (or to implement it yourself).<input>tag does not support drag-and-drop. You have to load a module to do that. The standard browser response to a dropped file is to open a new tab, as you have seen.<label for="fileInput">. So if the label registers file input, shouldn't the label's children?<input type="file">registered file drag and drops.