2

I hava an input of uploading file.

<input type="file" name="data" id="inFile" style="display: none"/>
<button type="button" name="btn" onClick="browse()">Choose file</button>

Browser will show a popup window of choosing file when the input is clicked.

I want to close the popup window using javascript or any JS library.

var timeout;
function browse(){
    var fileElem = document.getElementById("inFile");
    fileElem.click();
    timeout = setTimeout(closeWindow, 5000);
}

function closeWindow(){
    // close filepicker window if window is opened.
}

Can it be achieved? How to do? Thanks.

I want to close filepicker window automatically.

ludiusyan
  • 23
  • 5

1 Answers1

2

I'm afraid this might be impossible. For security purposes, the file browser dialog is invisible to JavaScript and all interaction with it must come from the user actually pressing mouse on the system dialog.

Matey
  • 1,190
  • 5
  • 7
  • I think so but i hava to face the problem. Thanks. – ludiusyan Dec 16 '16 at 09:35
  • What is the use case if I may ask? – Matey Dec 16 '16 at 09:39
  • We set up a time period for our site, if the user did not do anything in this time period, logout to the login page. However, if the system dialog exists, website will not logout. – ludiusyan Dec 17 '16 at 04:47
  • When the timer expires, you can send logout message to server and redirect client browser to a login page. This can be done regardless of whether the file browser dialog is open or not. – Matey Dec 19 '16 at 12:30