Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

515
Visualizações
html/js how to ask the user where to download a file

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.

example

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:

enter image description here

How can I replicate the first situation with JS and HTML?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

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.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda