What I need to do is programmatically hook into the file select dialog created when a user clicks on the button for input type file, without the user actually clicking on the button. The JavaScript would test if a file exists, and handle it as needed: read it, copy it, etc.
Asked
Active
Viewed 92 times
0
-
Could the file:// protocol be what you're looking for? – Graham P Heath Aug 30 '15 at 23:39
-
1Um, you want to just click the button or try selecting a file? Selelcting the file with JS is not going to happen... – epascarello Aug 31 '15 at 00:45
-
@epascarello Yes, I ultimately want JS to try and select a file autonomously - crawl the client's file system, effectively. – Guessed Aug 31 '15 at 02:43
-
@Guessed _"Yes, I ultimately want JS to try and select a file autonomously - crawl the client's file system, effectively. "_ This is not possible. See http://stackoverflow.com/a/29873845/ – guest271314 Aug 31 '15 at 03:03
1 Answers
-1
Try utilizing onchange
event to access File
object if user selects file ; js
cannot select user file .
var input = document.querySelector("[type=file]");
input.onchange = function() {
console.log(this.files)
}
<input type="file" />

guest271314
- 1
- 15
- 104
- 177
-
Since in the scenario presented the user does not click and therefore does not select a file either, what would trigger the onchange? – Guessed Aug 30 '15 at 23:39
-
@Guessed See http://stackoverflow.com/questions/29728705/trigger-click-on-input-file-on-asynchronous-ajax-done – guest271314 Aug 31 '15 at 00:14
-
@epascarello _"Because you did not answer the question...."_ ? See _"`js` cannot select user file"_ at post ? Similar to last sentence at comment http://stackoverflow.com/questions/32302210/what-is-the-javascript-equivalent-of-a-user-clicking-on-the-input-type-file-butt/32302224#comment52481312_32302210 ? see also `js` included at post which could access user file , if selected by user ? , link to SO Question , accepted Answer at second comment above . Can detail why solution , explaination at post does not answer question ? How could this answer be improved ? – guest271314 Aug 31 '15 at 00:54