javascript - How to download file in angularJS.For safari browser and edge browser -
i new angularjs.i want download json file.it working in chrome not in edge , safari.in safari file opening in browser only. reading. plz reply.
function itemexport() { var = document.createelement("a"); document.body.appendchild(a); //a.style = "display: none"; if ($scope.selectedrows.length > 0) { commonfactory.itemexport($scope.selectedrows, $scope.classname).then(function (data) { var json = json.stringify(data.data), blob = new blob([json], {type: "octet/stream"}); //url = window.url.createobjecturl(blob); var encodeduri = encodeuri("data:text/plain;charset=utf-8," + json); a.setattribute("href",encodeduri); if ($scope.selectedrows.length === 1) { commonfactory.getinstancebyuid($scope.domainuid, $scope.classuid, $scope.classname, $scope.selectedrows[0], $scope.iscorecomponents).then(function (inst) { a.setattribute("download", inst[0]._fields[0].properties.name+".json"); a.click(); window.url.revokeobjecturl(url); }); } else { a.download = $scope.classname+".json"; a.click(); window.url.revokeobjecturl(url); } }); } else { toastrfactory.warning('please select @ least 1 item export', 'warning'); } }
Comments
Post a Comment