I would like to make an html file that contains a button that when clicked, asks the user where to download a js generated file to. For example, here is a screenshot of my firefox browser prompting me to decide where I want to save a file I am about to download off a webpage.
Currently my solution is the following code:
<script>
function download(filename, text){
let element = document.createElement('a')
element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text))
element.setAttribute('download', filename)
element.click()
}
download("hello.txt","This is the content")
</script>
However the popup does not ask where to save the file to as seen here:
How can I replicate the first situation with JS and HTML?
This depends entirely on the browser's implementation and is not something you can control with Javascript.
In this case the user would have to select save file.