• Resolved hellothanos

    (@hellothanos)


    Hi there,

    I’m trying to download a CSV of my log entries in the admin area and via the Export button. Instead of a file download the .csv opens in a new tab. When I try to save it, it saves it as an html file.
    I tested this on Chrome v98 and Firefox v95.

    I saw in your source code that the csv is handled with javascript and with a bit of research I saw that using the download attribute could be a way of resolving this?:
    https://stackoverflow.com/questions/46638343/download-csv-file-as-response-on-ajax-request

    Many thanks,
    Thanos

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Pixelbart

    (@pixelbart)

    @hellothanos

    Thank you for your feedback! ??

    That is a good hint. I have directly installed and uploaded the update. Should then work.

    Stay healthy!

    Greetings Kevin

    Thread Starter hellothanos

    (@hellothanos)

    Hi Kevin,

    Thank you for the quick response and for sorting this!

    This works great – the only small issue is that the file is being downloaded with a .html extension. I’m guessing it’s because the Content-Type header of the file isn’t set to text/csv. I saw you’re using the wp_send_json function that sets the headers to application/json so not sure how you could go about this.

    A workaround that I tested and seems to work ok on chrome is setting the a.download attribute’s value to log.csv. Apparently though you’re not supposed to put extensions to the value https://www.w3schools.com/tags/att_a_download.asp ??

    Hope this helps,
    Thanos

    Plugin Author Pixelbart

    (@pixelbart)

    @hellothanos

    Hi Thanos,

    thanks again! I just changed that and uploaded an update. Maybe this will help you a bit. I had not put a name because MDN says it is not necessary. But if it works better that way, all the better.

    Stay healthy and have a good time!

    Greetings Kevin

    • This reply was modified 3 years ago by Pixelbart.
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘log export csv in new tab instead of download’ is closed to new replies.