我希望指向 .ics 文件的 HTML 链接在单击时在日历应用程序中打开,当前以纯文本形式打开文件。建议?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5329529/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 07:24:07  来源:igfitidea点击:

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

htmlhyperlinkcalendaricalendar

提问by Eric Knudtson

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

.ics在 HTML 网页中链接到从 Apple iCal 导出的文件。

<a href="calendar.ics">

This link will open the calendar.icsfile 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 .icsfiles?

此链接将calendar.ics在我的浏览器 (Chrome) 中以纯文本形式打开文件。我想在 Outlook 或 iCal 或其他日历应用程序中自动打开。为了产生所需的行为,我可以向链接标签添加什么?修改文件上的 HTTP 标头怎么样.ics

Any suggestions are appreciated!

任何建议表示赞赏!

采纳答案by Ryan Corbin

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.

如果您的网站像我一样是在 Linux 上构建的,您只需在 htaccess 文件中添加一行,使其作为下载而不是文本页面打开。

add this to your htaccess file:

将此添加到您的 htaccess 文件中:

AddType text/calendar .ics

回答by Michael - Where's Clay Shirky

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

如果您的日历文件不是静态的,您应该考虑webcal://Outlook 和 iCal 将处理的协议:

<a href="webcal://domain.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.

与会者的日历程序将定期轮询您的日历更新,而不是下载一次性文件。这将使他们的日历添加新事件并更新更改的事件以匹配您发布的列表。