1

I can't seem to download the pdf here. It just goes to a different window instead of downloading automatically. How do I save the PDF as a file instead of opening to a new window? Here's my code:

<p>
  <select id="scripts" name="scripts">
    <option disabled selected>Select to Download</option>
    <option value="http://concentrix.kinsta.cloud/wp-content/uploads/2020/12/CULTURE_symbolisms_bw_2018_AB_ver01_r01_09082020_us.pdf">Save as PDF</option>
    <option value="http://concentrix.kinsta.cloud/wp-content/uploads/2020/12/CULTURESTATEMENTS.zip">Save as JPG</option>
  </select>
</p>
<p style="text-align:center;">
  <input type="button" id="showVal" value="Download" />
</p>
<script>
  (function() {
    var sel = document.getElementById('scripts');
    function getSelectedOption(sel) {
      var opt;
      for (var i = 0, len = sel.options.length; i < len; i++) {
        opt = sel.options[i];
        if (opt.selected === true) {
          break;
        }
      }
      return opt;
    }
    document.getElementById('showVal').onclick = function() {
      window.location = sel.value;
    }
  }());
</script>

Thanks for the help!

Parth Raval
  • 4,097
  • 3
  • 23
  • 36
  • Does this answer your question? https://stackoverflow.com/a/9834261/13532354 – Misha Borisov Dec 10 '20 at 11:21
  • Since you are already clicking a button to download, you could replace that with a download link (``) [Related question here](https://stackoverflow.com/questions/2793751/how-can-i-create-download-link-in-html) – DBS Dec 10 '20 at 11:25
  • look it - https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/downloads/download – s.kuznetsov Dec 10 '20 at 11:54

0 Answers0