Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I want HTML link to .ics file to open in calendar app when clicked, currently opens file as plain text. Suggestions?

I am linking to an .ics file exported from Apple iCal in an HTML web page.

<a href="calendar.ics"> 

This link will open the calendar.ics file as plain text in my browser (Chrome). I want automatic opening in Outlook or iCal or other calendar apps. What can I add to the link tag in order to produce the desired behavior? What about modifying the HTTP headers on .ics files?

Any suggestions are appreciated!

like image 697
Eric Knudtson Avatar asked Mar 16 '11 17:03

Eric Knudtson


People also ask

What is a URL of the .ics file?

What is an ICS / iCal Feed URL? Most calendar programs allow you to export an iCalendar (. ics or iCal) feed URL. This feed URL contains event data (like times, dates, location, title, description, and time zone) in a standard format. Also each event has a unique identifier or "UID".


2 Answers

If your calendar file is not static, you should consider the webcal:// protocol, which Outlook and iCal will handle:

<a href="webcal://example.com/path/calendar.ics"> 

Rather than downloading a one-time file, the attendees' calendar programs will periodically poll for updates to your calendar. This will let their calendars add new events and update changed events to match your published list.

like image 142
Michael Avatar answered Sep 30 '22 12:09

Michael


If your site is built on Linux like mine you can simply add a line to your htaccess file to make it open as a download instead of a text page.

add this to your htaccess file:

AddType text/calendar .ics 
like image 39
Ryan Corbin Avatar answered Sep 30 '22 12:09

Ryan Corbin