I have a map web application and want to save route data in a GPX file. To do this, I create an anchor tag containing the data, and using the HTML5 download property to set the file name. This works as expected in OS X (10.9.4) in both Firefox (29.0.1) and Chrome (37.0.2062.94), but in Safari (7.0.6) it ignores the name in the download attribute and saves the file with the name just "Unknown."
This is the link in my HTML file:
<a href="#" id="map_save">Save to GPX</a>
This is how it is linked in my Javascript file (using jQuery):
function exportToGPX( gpxData ) { gpxData = 'data:application/gpx+xml;charset=utf-8,' + encodeURIComponent( gpxData ); $( '#map_save' ).attr( { 'href': gpxData ,'download': 'myfile.gpx' } ); } $( document ).ready( function() { $( '#map_save' ).click( function( event ) { exportToGPX.apply(); } ); } );
All that I saw suggests that Safari must abide by this attribute, and this is apparently not a WebKit problem if it works in Chrome. Using the Web Inspector to view the DOM tree shows that the attribute is correctly applied:
<a href=โ"data:โapplication/โgpx+xml;โchโฆ09%3C%2Ftrk%3E%0A%3C%2Fgpx%3E" id=โ"map_save" download=โ"myfile.gpx">โSave to GPXโ</a>โ
As I said, it downloads the file, just without specifying its name. Is there something I'm doing wrong or need to be done to make this work properly in Safari?
source share