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.

2
  • Please show the dialog part, it's merely an input component. Commented Dec 16, 2016 at 8:48
  • The dialog is file window of system. Commented Dec 16, 2016 at 9:15

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

4 Comments

I think so but i hava to face the problem. Thanks.
What is the use case if I may ask?
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.
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.