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

81,540

Solution 1

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

Solution 2

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.

Share:
81,540

Related videos on Youtube

Eric Knudtson
Author by

Eric Knudtson

Updated on July 09, 2022

Comments

  • Eric Knudtson
    Eric Knudtson almost 2 years

    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!

    • justkt
      justkt about 13 years
      What is the HTTP Content-Type header on your response right now? It should be text/calendar.
    • Eric Knudtson
      Eric Knudtson about 13 years
      The header in the response is 'text/plain' when simply linking to the .ics file.
    • justkt
      justkt about 13 years
      can you get your server to serve it up as text/calendar and see if that gets your client browser to treat it properly?
    • Eric Knudtson
      Eric Knudtson about 13 years
      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.
    • matt b
      matt b about 12 years
      to have browsers treat a link as a download, you should add the Content-Disposition:attachment header, optionally with a filename argument. stackoverflow.com/questions/1012437/…
  • PiTheNumber
    PiTheNumber about 11 years
    Looks like IE does not support this in 2005. How is the support now?
  • Michael
    Michael almost 11 years
    @PiTheNumber With no additional verification, it sounds like 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 file is not going to help you much.
  • Kaivosukeltaja
    Kaivosukeltaja over 9 years
    This doesn't work with current Android devices either.
  • Krafty
    Krafty about 9 years
    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.
  • Daniel Viglione
    Daniel Viglione about 8 years
    This is exactly what I was looking for!
  • The Onin
    The Onin about 7 years
    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): <a href="webcal://path/to/.ics">sub link</a>
  • amarinediary
    amarinediary almost 3 years
    You can refer to the CanIUse for browser support, @see caniuse.com/?search=registerProtocolHandler