I have an input element (Dropzone) that's hidden, and is written in the original html's body (was not appended).
<div style="display: none;">
<form action="/uploadProfile" method="post" class="dropzone" id="uploadProfileDropzone"></form>
</div>
Now inside my .js script, I'm trying:
$(function() {
$('#uploadProfileDropzone').click()
})
And nothing happens. However, if I'm calling $('#uploadProfileDropzone').click()
inside Chrome's console, it works.
What could possibly be the problem?
EDIT:
Problem might be that I'm trying to call the function before my Dropzone has initialized. Is there a way to know when this happens?
However, even when trying:
$(function() {
setTimeout(function() {
$('#uploadProfileDropzone').click()
}, 5000)
})
Which is a lot after the page fully loads, still nothing happens
SOLUTION:
It turns out that some (or even most of the) browsers block such activity. It's pretty obvious why, looking back at it now. My intention was to navigate to a page that once ready, opens a file dialog for a profile upload action. It seems logically correct to block such action from a user experience point of view, as it can lead to spam and undesired activity from websites. I solved it by displaying a simple popup box on load, that forces the user to press a button, that in turn calls $('#uploadProfileDropzone').click()
and it worked.