Skip to content

Javascript-generated .ics file opens in Chrome and Firefox, but not in IE

I’m generating a .ics calendar entry from JS, next I open it using a data-URI:"data:text/calendar;charset=utf8," + escape(icsMSG));

Where “icsMSG” is the dynamically generated .ics file. Here’s a sample output from console.log:

PRODID:-// v1.0//EN
LOCATION:5384 DA Heesch, The Netherlands
SUMMARY:JungleDragon Daylight Event
DESCRIPTION:Hey you!   n n  At this time in your calendar light conditions are great for the location you selected:n n shooting, and be sure to share your wildlife photos back to http://www.jungledragon.comnCheers,nThe JungleDragon Team

The raw output will be have n chars at the end of each line, as per the specification.

The above sample works fine when I run it from Chrome or Firefox, in both case it will open up my default Calendar application (Outlook 2013). In IE(11) and Opera, instead something weird happens. A new tab opens that has the above string as the URL, with all special chars URL-escaped. Like so:


Next, the new tab is blank and nothing happens. I’m not sure whether there is a syntax mistake in my .ics, but given that it works for Chrome and Firefox, I don’t believe so.

Any thoughts?

Edit, extra info: If I manually open a downloaded .ics file with the exact same content, it does work also in IE and Opera. Something must be wrong with the way I open it using



Answering my own question:

The problem was not in the .ics output itself, rather it was in IE and Opera not treating the js-generated output as a file to download. To enforce such a download, is only possible from a server-side script.

I ended up recoding my logic to output the .ics file on the server-side, and by enforcing these headers:

header('Content-type: text/calendar; charset=utf-8');
header('Content-Disposition: attachment; filename=cal.ics');

It was a painful restructuring, but now it works across browsers.

User contributions licensed under: CC BY-SA
3 People found this is helpful