3

I have this code in a button:

var csvContent = "data:text/csv;charset=utf-8,";
csvContent += myCSVcontent;

var encodedUri = encodeURI(csvContent);
window.open(encodedUri);

This works perfectly in Chrome, Safari, and Firefox.
- But not IE8 - I need Internet Explorer 8 compatibility.

When I click the button that calls the code above it downloads the .csv file to my computer.
When I click the button in IE8 though, it opens a new IE8 window with all the csv contents in the address bar and does not download (or ask to download) anything.

Unfortunately, I have to have IE8 compatibility. How can I make this work?

Edit: I must avoid any additional calls to the server. Everything needs to happen client side. This is currently working in all browsers except IE8 (and possibly IE9).

Edit2: When I change the last line to "document.location.href= encodedUri;" it will still work on all other browsers but in IE8 when I click the button I get an error window that says "The data area passed to a system call is too small." Any idea what that is telling me?

Uncle Iroh
  • 4,961
  • 4
  • 43
  • 55
Jack Hillard
  • 536
  • 10
  • 24
  • possible duplicate of [Utility of HTTP header "Content-Type: application/force-download" for mobile?](http://stackoverflow.com/questions/10615797/utility-of-http-header-content-type-application-force-download-for-mobile) – Laurent S. Dec 30 '13 at 16:18
  • In Chrome this is blocked as a pop-up (at least in v35 it is). – Warpling May 29 '14 at 15:57

1 Answers1

0

"data:text/csv;" is HTML5 so it will not work for IE8, i'm able to solve this using ActivexObject, but it's writing the file to user's desktop and no popup

var csv = new ActiveXObject("scripting.FileSystemObject");
var fLoc = csv.CreateTextFile(fileName);
fLoc.WriteLine(csvData);
fLoc.close();
bhasky
  • 11
  • 1