3

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?

3
  • Maybe this helps: stackoverflow.com/questions/25684370/display-csv-file-in-html Commented Nov 28, 2020 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. Commented Nov 28, 2020 at 14:19
  • i think yo have to set header because With a Code like this: <a href="Myfile.csv">Open</a>, 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 Commented Nov 28, 2020 at 14:19

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.