1

I just have a problem with my project. I have created three columns with xml, json and csv descriptions, and below each of them there is a button which is supposed to load the data from local storage. The thing is, the following code works as expected in .xml and .json file (everything the same, just different url), but with .csv the browser starts downloading the file instead of opening it in the new window.

<div class="card" style="width: 100%;">
  <img class="card-img-top" src="./assets/CSV.png" alt="csv-logo">
  <div class="card-body">
    <h2 class="card-title text-danger">CSV</h2>
    <p class="card-text new-font">Coma Separated Values Description</p>
    <a href="./data/MOCK_DATA.csv" target="_blank">
        <button class="btn btn-dark py-3 px-4" type="button">
        <span class="button-text">Load data</span>
        </button>
    </a>
</div>
</div>

Do you guys have any ideas how to fix it? Or maybe it's natural browser behaviour, so in this case how to change it?

Abgar
  • 93
  • 1
  • 7
  • Maybe this helps: https://stackoverflow.com/questions/25684370/display-csv-file-in-html – Magofoco Nov 28 '20 at 14:17
  • if you must display it, find another way (rename, txt, a file parser...), because a link is how you tell the browser : "Please handle this for me" since it can parse those files, it will open then in new window, for your csv file it can't so it will download it. – phoenixstudio Nov 28 '20 at 14:19
  • i think yo have to set header because With a Code like this: Open, You are really not doing any download. However, if the Client Browser doesn't have the capability to read/render the File (in this case .csv File), it will force the user to download the file instead – BugsCreator Nov 28 '20 at 14:19

0 Answers0