Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSV downloading in Safari browser

Tags:

html

safari

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.

like image 842
RydelHouse Avatar asked Jun 09 '15 07:06

RydelHouse


1 Answers

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...)

like image 95
Adriano Repetti Avatar answered Sep 28 '22 09:09

Adriano Repetti