0
我的应用程序允许用户将GeoJSONs导出为.json文件...在Chrome和Firefox中下载工作正常,但在Safari中,用户被导向至data:text/ + GEOJSON STRING
并且GeoJSON的文本呈现在页面上 - 完全没有下载。Safari - 数据导出/ html下载属性不起作用
$('#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();
};
因此而不是触发下载的href
datasStr
,因为它在其他浏览器的确,Safari浏览器对待href
属性作为URL链接。
任何我可以在Chrome,Firefox和Safari上正常运行的方式?
尝试filesaver.js“库” –
请参阅http://stackoverflow.com/questions/38711803/how-to-download-a-file-without-using-a-element-with-download-attribute-or -a-SE – guest271314