0

My app allows users to export GeoJSONs as .json files... the download works just fine in Chrome and Firefox, but in Safari, the user is directed to a url with data:text/ + GEOJSON STRING and the text of the GeoJSON is rendered on the page - no download at all.

$('#export_table > tbody > tr > td').each(function(){
    geoObject = JSON.parse($(this).html());
    layerName = geoObject.name;
    exportRowToGeoJSON($(this).html(), layerName);
});

function exportRowToGeoJSON(storageObj, fileName){
    dataStr = "data:text/json;charset=utf-8," + encodeURIComponent(storageObj);
    link = document.createElement('a');
    link = document.body.appendChild(link); //FOR FIREFOX
    link.setAttribute("href", dataStr);
    link.setAttribute("download", fileName + ".json");
    link.click();
};

So rather than triggering a download of the href datasStr as it does in the other browsers, Safari treats the href attribute as a url to link to.

Any way that I can get this functioning properly across Chrome, Firefox, and Safari?

skwidbreth
  • 7,888
  • 11
  • 58
  • 105

1 Answers1

-2

Please look at w3schools.com

As you can see, you must be using a version of Safari that is under 10.1, correct? Is so, I do recommend updating your browser, or switch to Chrome, Firefox, or Opera.

Any version lower than 10.1 in safari has no support for HTML5 attributes/tags, which is why some websites require and updated browser.

EgMusic
  • 136
  • 17