I want HTML link to .ics file to open in calendar app when clicked, currently opens file as plain text. Suggestions?
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.
Related videos on Youtube
Eric Knudtson
Updated on July 09, 2022Comments
-
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 about 13 yearsWhat is the HTTP Content-Type header on your response right now? It should be
text/calendar
. -
Eric Knudtson about 13 yearsThe header in the response is 'text/plain' when simply linking to the .ics file.
-
justkt about 13 yearscan 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 about 13 yearsThe 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 about 12 yearsto have browsers treat a link as a download, you should add the
Content-Disposition:attachment
header, optionally with afilename
argument. stackoverflow.com/questions/1012437/…
-
-
PiTheNumber about 11 yearsLooks like IE does not support this in 2005. How is the support now?
-
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 over 9 yearsThis doesn't work with current Android devices either.
-
Krafty about 9 yearsWhen 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 about 8 yearsThis is exactly what I was looking for!
-
The Onin about 7 yearsOk 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 almost 3 yearsYou can refer to the CanIUse for browser support, @see caniuse.com/?search=registerProtocolHandler