Search code examples
javascriptcsvinternet-explorer-10window.open

window.open not working in IE10


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.


Solution

  • 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