27

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!

Michael
  • 8,362
  • 6
  • 61
  • 88
Eric Knudtson
  • 2,204
  • 2
  • 18
  • 12
  • 1
    What is the HTTP Content-Type header on your response right now? It should be `text/calendar`. – justkt Mar 16 '11 at 18:03
  • The header in the response is 'text/plain' when simply linking to the .ics file. – Eric Knudtson Mar 22 '11 at 14:48
  • can you get your server to serve it up as `text/calendar` and see if that gets your client browser to treat it properly? – justkt Mar 22 '11 at 14:50
  • The files are being served from a typical shared host PHP LAMP type environment. How would I modify the headers on something like that? I'm not sure I can even use mod-rewrite or give Apache any config options. – Eric Knudtson Mar 22 '11 at 14:58
  • 3
    to have browsers treat a link as a download, you should add the `Content-Disposition:attachment` header, optionally with a `filename` argument. http://stackoverflow.com/questions/1012437/uses-of-content-disposition-in-an-http-response-header – matt b Apr 25 '12 at 15:04

2 Answers2

35

If your calendar file is not static, you should consider the webcal scheme in addition to setting the MIME type to text/calendar in Ryan's answer.

<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.

Support

  • Calendar applications like Outlook and iCal can sign up to handle links with that scheme.

  • In many desktop browsers, a website like Google Calendar can also handle webcal links.

  • iOS can import calendar events with webcal and a text/calendar type.

  • Android is an odd case:

    • Despite a merge request to add file support to AOSP, it was never put in.
    • Third party packages like ICSx5 can sign up to subscribe to a webcal and provide the events to the user's primary calendar application.
Michael
  • 8,362
  • 6
  • 61
  • 88
  • [Looks like](http://www.stefanhayden.com/blog/2005/08/08/my-adventures-with-hcal-ical-webcal-and-their-lack-of-support/) IE does not support this in 2005. How is the support now? – PiTheNumber May 08 '13 at 14:27
  • @PiTheNumber With no additional verification, it [sounds like](http://news.mullerdigital.com/2010/03/08/webcal-link-in-ie/) you need Outlook 2007+ or some other program that signs up to handle the `webcal` protocol on your computer. It's not IE, it's "Do you have something to handle `.ics` files?" In the absence of such a program, an [RFC 5545](http://tools.ietf.org/html/rfc5545) file is not going to help you much. – Michael May 08 '13 at 19:46
  • 5
    This doesn't work with current Android devices either. – Kaivosukeltaja Aug 27 '14 at 18:12
  • When I put this in IE I get a Chrome popup and when I let it open the ics file it just opens a blank tab. – Krafty Apr 23 '15 at 06:02
  • This is exactly what I was looking for! – Daniel Viglione Apr 01 '16 at 22:54
  • 2
    Ok here's the thing: Chrome recognizes it as well if you put it into a link (as opposed to putting it directly into address bar and hitting enter): `sub link` – The Onin May 07 '17 at 21:09
  • 1
    You can refer to the CanIUse for browser support, @see https://caniuse.com/?search=registerProtocolHandler – amarinediary Jul 29 '21 at 16:25
8

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
Smern
  • 18,746
  • 21
  • 72
  • 90
Ryan Corbin
  • 96
  • 1
  • 1