jquery data to csv

I have this code to open data in Excel, in csv format, seems to work fine in Firefox, does not work in IE 9 or 10.  Is there anything that can be done  ?

        var uri = 'data:application/vnd.ms-excel,' + html;
        var downloadLink = document.createElement("a");
        downloadLink.href = uri;
        downloadLink.download = "Export.csv";

Open in new window

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Rainer JeschorCommented:
sorry but I don't have working code at hand, but the main functionality could be found at the Angular UI GitHub repository:

Please scroll down to the last 3-4 comments.
Rainer JeschorCommented:

the following code would need a little bit of cleanup but should work in general:

function CreateExcelLikeAngular(fileName, csvContent) {
          var D = document;
          var a = D.createElement('a');
          var strMimeType = 'application/octet-stream;charset=utf-8';
          var rawFile;

          if (!fileName) {
            var currentDate = new Date();
            fileName = "CSV Export - " + currentDate.getFullYear() + (currentDate.getMonth() + 1) +
                          currentDate.getDate() + currentDate.getHours() +
                          currentDate.getMinutes() + currentDate.getSeconds() + ".csv";

          if (isIEBelow10()) {
            var frame = D.createElement('iframe');

            frame.contentWindow.document.open("text/html", "replace");
            frame.contentWindow.document.write('sep=,\r\n' + csvContent);
            frame.contentWindow.document.execCommand('SaveAs', true, fileName);

            return true;

          // IE10+
          if (navigator.msSaveBlob) {
            return navigator.msSaveBlob(new Blob(["\ufeff", csvContent], {
              type: strMimeType
            }), fileName);

          //html5 A[download]
          if ('download' in a) {
            var blob = new Blob([csvContent], {
              type: strMimeType
            rawFile = URL.createObjectURL(blob);
            a.setAttribute('download', fileName);
          } else {
            rawFile = 'data:' + strMimeType + ',' + encodeURIComponent(csvContent);
            a.setAttribute('target', '_blank');
            a.setAttribute('download', fileName);

          a.href = rawFile;
          a.setAttribute('style', 'display:none;');
          setTimeout(function() {
            if (a.click) {
              // Workaround for Safari 5
            } else if (document.createEvent) {
              var eventObj = document.createEvent('MouseEvents');
              eventObj.initEvent('click', true, true);

          }, 100);
function isIEBelow10() {
	var myNav = navigator.userAgent.toLowerCase();
    return (myNav.indexOf('msie') != -1) ? parseInt(myNav.split('msie')[1]) < 10 : false;

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
DemosthenesAuthor Commented:
I copy pasted your code as is, and it works.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.