Reputation: 71
I have some problems to implement a solution to by-pass the missing behaviour of "download" attribute in Internet Explorer.
Users can download three types of files :
So no problem in Chrome and FF. It works like this :
var tempCSV = json2CSV(geojson);
var csv = "text/csv;charset=utf-8," + encodeURIComponent(tempCSV);
$('#downloadCSV').attr('href', "data:" + csv);
As IE is not doing things like everyone else, I use msSaveBlob to deal with it like this :
if (navigator.msSaveBlob) {
var blobCSV = new Blob([tempCSV]);
$('#downloadCSV').click(function (e) {
navigator.msSaveBlob(blobCSV, "geo.csv");
e.preventDefault();
});
It works correctly for CSV and KML files. But not with geoJSON. I get an error with this line :
var blobGeoJSON = new Blob([tempGeoJSON]);
And I get this error : "InvalidStateError"
From where problem could come ?
Upvotes: 3
Views: 863
Reputation: 71
Ok, finally after reading again my code, I found the problem.
You have to stringify your json before create a blob with it, like this :
var tempGeoJSON = JSON.stringify(geojson);
Instead of this :
var tempGeoJSON = geojson;
Upvotes: 1