From 4c6da1a80506c5343596923b814f01badf215b78 Mon Sep 17 00:00:00 2001 From: Ali Rezvani <3788964+aliagamon@users.noreply.github.com> Date: Wed, 13 Jun 2018 13:47:04 +0430 Subject: [PATCH 1/2] Fixed download problem --- dist/js/jquery.jexcel.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/dist/js/jquery.jexcel.js b/dist/js/jquery.jexcel.js index 6ef1bf44..432cebe9 100644 --- a/dist/js/jquery.jexcel.js +++ b/dist/js/jquery.jexcel.js @@ -3862,12 +3862,14 @@ var methods = { data += $(this).jexcel('copy', false, ',', true); // Download elment - var pom = document.createElement('a'); - var blob = new Blob([data], {type: 'text/csv;charset=utf-8;'}); - var url = URL.createObjectURL(blob); - pom.href = url; - pom.setAttribute('download', options.csvFileName + '.csv'); - pom.click(); + var a = $(''); + a.attr('download', options.csvFileName + '.csv'); + a.attr('href', 'data:text/csv;charset=utf-8,\uFEFF' + encodeURIComponent(data)); + a.attr('target', '_blank'); + a.hide(); + $('body').append(a); + a[0].click(); + a.remove(); }, /** From 63e9be123fef9311d8196f39a5db28948a4adc8a Mon Sep 17 00:00:00 2001 From: Ali Rezvani <3788964+aliagamon@users.noreply.github.com> Date: Wed, 13 Jun 2018 14:12:11 +0430 Subject: [PATCH 2/2] Found the real problem with blob and fixed it using blob. in firefox you have to append element before clicking on it unlike chrome. also there was a problem with UTF-8 char-set, fixed it by adding UTF-8 BOM at the beginning of file. --- dist/js/jquery.jexcel.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/dist/js/jquery.jexcel.js b/dist/js/jquery.jexcel.js index 432cebe9..eafc9ea3 100644 --- a/dist/js/jquery.jexcel.js +++ b/dist/js/jquery.jexcel.js @@ -3862,14 +3862,14 @@ var methods = { data += $(this).jexcel('copy', false, ',', true); // Download elment - var a = $(''); - a.attr('download', options.csvFileName + '.csv'); - a.attr('href', 'data:text/csv;charset=utf-8,\uFEFF' + encodeURIComponent(data)); - a.attr('target', '_blank'); - a.hide(); - $('body').append(a); - a[0].click(); - a.remove(); + var pom = document.createElement('a'); + var blob = new Blob(["\uFEFF"+data], {type: 'text/csv;charset=utf-8;'}); + var url = URL.createObjectURL(blob); + pom.href = url; + pom.setAttribute('download', options.csvFileName + '.csv'); + document.body.appendChild(pom); + pom.click(); + document.body.removeChild(pom); }, /**