create .ics file on the fly using javascript or jquery? create .ics file on the fly using javascript or jquery? javascript javascript

create .ics file on the fly using javascript or jquery?


you will need to make it in ICS format. also you will need to convert the date and time zone; E.G. 20120315T170000Z or yyyymmddThhmmssZ

    msgData1 = $('.start-time').text();    msgData2 = $('.end-time').text();    msgData3 = $('.Location').text();    var icsMSG = "BEGIN:VCALENDAR\nVERSION:2.0\nPRODID:-//Our Company//NONSGML v1.0//EN\nBEGIN:VEVENT\nUID:me@google.com\nDTSTAMP:20120315T170000Z\nATTENDEE;CN=My Self ;RSVP=TRUE:MAILTO:me@gmail.com\nORGANIZER;CN=Me:MAILTO::me@gmail.com\nDTSTART:" + msgData1 +"\nDTEND:" + msgData2 +"\nLOCATION:" + msgData3 + "\nSUMMARY:Our Meeting Office\nEND:VEVENT\nEND:VCALENDAR";    $('.test').click(function(){        window.open( "data:text/calendar;charset=utf8," + escape(icsMSG));    });

the above sample will create a ics file for download. the user will have to open it and outlock, iCal, or google calendar will do the rest.


This is an old question, but I have some ideas that could get you started (or anyone else who needs to do a similar task).

And the JavaScript to create the file content, and open the file:

var filedata = $('.start-time, .end-time, .Location').text();window.open( "data:text/calendar;charset=utf8," + escape( filedata ) );

Presumably you'd want to add that code to the onclick event of a form button.

I don't have Outlook handy, so I'm not sure if it will automatically recognize the filetype, but it might.

Hope this helps.


From what I have found online and on this site, it is not possible to get this to work in IE as you need to include certain headers to let IE know to download this file.

The window.open method works for Chrome and Firefox but not IE so you may need to restructure your code to use a server-side language to generate and download the ICS file.

More can be found in this question