javascript - Download text/csv content as files from server in Angular not working in Mozilla FireFox -


download text/csv content files server in angular

answered - https://stackoverflow.com/users/2064206/dcodesmith

$http({method: 'get', url: '/someurl'}).   success(function(data, status, headers, config) {      var anchor = angular.element('<a/>');      anchor.attr({          href: 'data:attachment/csv;charset=utf-8,' + encodeuri(data),          target: '_blank',          download: 'filename.csv'      })[0].click();    }).   error(function(data, status, headers, config) {     // if there's error should see here   }); 

i implemented solution downloading files server client using angular. working fine in google chrome. solution not working in mozilla firefox.

thanks

you have attach anchor created document first. add followings:

var anchor = angular.element('<a/>'); anchor.css({display: 'none'}); // make sure it's not visible angular.element(document.body).append(anchor); // attach document  anchor.attr({     href: 'data:attachment/csv;charset=utf-8,' + encodeuri(data),     target: '_blank',     download: 'filename.csv' })[0].click();  anchor.remove(); // clean afterwards 

fiddle


Comments

Popular posts from this blog

python - Healpy: From Data to Healpix map -

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -