RydelHouse
RydelHouse

Reputation: 362

CSV downloading in Safari browser

How to create download links for CSV file downloading in Safari browsers?

Right now download link is this:

<a href="http://localhost/uploads/user-import-template/SupportUs_user_import.csv">download CSV template</a>

Problem is that this link opens CSV file in same browser tab, instead of downloading it.

Upvotes: 7

Views: 7669

Answers (1)

Adriano Repetti
Adriano Repetti

Reputation: 67090

Just add the download attribute:

<a download="SupportUs_user_import.csv"
   href="http://www.example.com/SupportUs_user_import.csv">download CSV template</a>

Please note it's an attribute new in HTML 5 and it may not be supported in some browsers. Where unsupported (you can check client-side with modernzr) you must use server side code to add "Content-Disposition" HTTP header with "attachment; filename=SupportUs_user_import.csv". If your file is static you can also configure your web server to add that HTTP header.

Currently (2017) it's not supported by IE11, desktop Safari before version 10.1, Safari for iOS and Opera Mini (source: Can I use...)

Upvotes: 9

Related Questions