Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
<!DOCTYPE html>
<html lang="en">
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- call the `ical_download()` function to create and download the .ics file -->
<button style="font-size:32px;" onclick="ical_download()">Download</button>
//where the magic happens
function ical_download(){
//name of event in iCal
this.eventName = 'My Cool Event';
//name of file to download as
this.fileName = 'my-event.ics';
//start time of event in iCal
this.dateStart = '2016-04-01';
//end time of event in iCal
this.dateEnd = '2016-04-02';
//helper functions
//iso date for ical formats
this._isofix = function(d){
var offset = ("0"+((new Date()).getTimezoneOffset()/60)).slice(-2);
if(typeof d=='string'){
return d.replace(/\-/g, '')+'T'+offset+'0000Z';
return d.getFullYear()+this._zp(d.getMonth()+1)+this._zp(d.getDate())+'T'+this._zp(d.getHours())+"0000Z";
//zero padding for data fixes
this._zp = function(s){ return ("0"+s).slice(-2); }
this._save = function(fileURL){
if (!window.ActiveXObject) {
var save = document.createElement('a');
save.href = fileURL; = '_blank'; = this.fileName || 'unknown';
var evt = new MouseEvent('click', {
'view': window,
'bubbles': true,
'cancelable': false
(window.URL || window.webkitURL).revokeObjectURL(save.href);
// for IE < 11
else if ( !! window.ActiveXObject && document.execCommand) {
var _window =, '_blank');
_window.document.execCommand('SaveAs', true, this.fileName || fileURL)
var now = new Date();
var ics_lines = [
"PRODID:-//Addroid Inc.//iCalAdUnit//EN",
var dlurl = 'data:text/calendar;base64,'+btoa(ics_lines.join('\r\n'));
try {
Copy link

when i click download that file has been downloaded but that file not open

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment