2

I'm trying to convert json to csv, based on this post. Everything works fine in Chrome and Firefox except IE10. Window.open doesn't seem to work in IE10.

window.open( "data:text/csv;charset=utf-8," + escape(str)); 

where str is my csv string

A new blank tab is opened with url "data:text/csv;charset=utf-8,xxxxxxxxxxxx" where "xxxx" is the encoded csv string. I have also tried:

var uri = 'data:text/csv;charset=utf-8,' + encodeURIComponent(str);
var downloadLink = document.createElement("a");
downloadLink.href = uri;
downloadLink.download = "OpHis.csv";
document.body.appendChild(downloadLink);
downloadLink.click();
document.body.removeChild(downloadLink);

with same result working in Chrome, Firefox but not in IE10. Any help is appreciated.

Community
  • 1
  • 1
user1167267
  • 23
  • 1
  • 5
  • Check your browser's console for any errors – Ian Jul 23 '13 at 14:15
  • By the way, the `download` attribute/property isn't supported until IE11, so that's why your second snippet doesn't work: http://caniuse.com/download – Ian Jul 23 '13 at 14:16
  • Here's my example: http://jsfiddle.net/FZZvs/ , and this is the warning I get: `HTML1524: Invalid DOCTYPE. The shortest valid doctype is " ". unknownprotocol.htm, line 1 character 1` – Ian Jul 23 '13 at 14:20
  • possible duplicate of [Data URI scheme and Internet Explorer 9 Errors](http://stackoverflow.com/questions/7405345/data-uri-scheme-and-internet-explorer-9-errors) – Ian Jul 23 '13 at 14:23
  • same behavior the url is data:text/csv;charset=utf-8,asdf%2Cfdsa%2Casdf – user1167267 Jul 23 '13 at 14:29
  • Yeah, that was my point. I just wanted to provide an example to test. According to my last comment about being a duplicate, this doesn't seem possible in IE – Ian Jul 23 '13 at 14:30

1 Answers1

0

this solved my problem on ie10

window.navigator.msSaveOrOpenBlob(blobObject, 'msSaveBlobOrOpenBlob_testFile.txt');

you can find more information on this link http://msdn.microsoft.com/en-us/library/ie/hh779016(v=vs.85).aspx

user1167267
  • 23
  • 1
  • 5