How to make download routine?

Asked

Viewed 37 times

0

Good afternoon, dear friends !

I’m starting programming in javascript!

I started with something simple !!

A file download routine , where the idea is, by choosing the file to download , after checking whether the file exists or not , with message !

My code got bizarre I know !! but it’s for those who want to help me !!

<html>
  
<section id="conteudo">
       <select id="opcao">  
        <option>Selecione</option> <tr>
    <option value="209901">JAN/2099</option>
    <option value="202002">FEV/2020</option>
    <option value="202003">MAR/2020</option>
    <option value="202004">ABR/2020</option>
    <option value="202005">MAI/2020</option>
    <option value="202006">JUN/2020</option>
    <option value="202007">JUL/2020</option>
    <option value="202008">AGO/2020</option>
    <option value="202009">SET/2020</option>
    <option value="202010">OUT/2020</option>
    <option value="202011">NOV/2020</option>
    <option value="202012">DEZ/2020</option>
    
    </select>


<button onclick="clickyClick()">Baixar Indice</button> <tbr>



   
<script type='text/javascript'>

        function clickyClick() {
          url = 'http://www.quarta.com.br/downloads/gfip/'+"TF" + document.getElementById("opcao").value+".zip"
         <script url='http://www.quarta.com.br/downloads/gfip/'+"TF" + document.getElementById("opcao").value+".zip" onerror="alert('Indice não disponilizado');" onload="window.open(url, '_blank');" type="text/javascript" ></script>
       
   

</script>
    
  
</html>

1 answer

0

I don’t know if I understand what you want to do, but come on.

One thing you can do, is take this url, and put it inside the href of a Hyperlink, along with the download attribute.

<a href="http:UrlLinkblablabla" download style="display: none"></a>

Then just use logic to do whatever you want with it. I imagine you want to download the file as soon as you click the button. So within your "clickyClick" function, you can pass the URL inside the Hyperlink href through a little Javascript, and then give a Trigger click (also through Javascript) on Hyperlink

Browser other questions tagged

You are not signed in. Login or sign up in order to post.