将事件添加到谷歌日历、雅虎日历、Outlook 和 ical

发布于 2024-10-20 05:59:39 字数 1539 浏览 2 评论 0 原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

日裸衫吸 2024-10-27 05:59:39

今晚我一直在寻找类似的东西,发现这个 jQuery 插件似乎可以帮助你。您可以使用它“即时”直接生成 .ics 文件,这对 Google、Outlook、iCal 和 Yahoo 应该很有用。

http://keith-wood.name/icalendar.html

我还没有机会虽然我自己测试了一下,但计划在接下来的几天内进行。然而HTH!

I've been searching for something similar tonight and found this jQuery plugin which seems that could help you out. You can directly generate .ics files "on the fly" with it which should be good for Google, Outlook, iCal and Yahoo.

http://keith-wood.name/icalendar.html

I haven't had a chance to test it myself though, but plan to do it in the next days. However HTH!

メ斷腸人バ 2024-10-27 05:59:39

对于纯 JavaScript 解决方案,有 ics.js。它仅使用 javascript 生成 ics 文件。唯一的缺点是它不支持旧版本的 IE。

For a pure javascript solution, there is ics.js. It generates ics files using solely javascript. The only downside is that it doesn't support older versions of IE.

泪冰清 2024-10-27 05:59:39

这是我使用的内容,以防它对任何人有帮助,我使用的是 ASP.NET MVC / C#,但应该为您提供自行构建它所需的要点。

展望与展望iCal:

var icsUrl = '/todos/geticsfile/' + id;

public ActionResult GetIcsFile(string id) {
            var user = UserService.Get(UserId);
            var todo = ToDoService.Get(id);
            var content = GetOutlookFileContents(user, todo);
            var bytes = Encoding.UTF8.GetBytes(content);
            return File(bytes, "text/calendar", "housters-todo.ics");
        }

public static string GetOutlookFileContents(User user, ToDo todo) {
            var builder = new StringBuilder();

            builder.AppendLine("BEGIN:VCALENDAR");
            builder.AppendLine("METHOD:REQUEST");
            builder.AppendLine("PRODID:Microsoft Exchange Server 2010");
            builder.AppendLine("VERSION:2.0");
            builder.AppendLine("BEGIN:VTIMEZONE");
            builder.AppendLine("TZID:Eastern Standard Time");
            builder.AppendLine("BEGIN:STANDARD");
            builder.AppendLine("DTSTART:16010101T020000");
            builder.AppendLine("TZOFFSETFROM:-0700");
            builder.AppendLine("TZOFFSETTO:-0800");
            builder.AppendLine("RRULE:FREQ=YEARLY;INTERVAL=1;BYDAY=1SU;BYMONTH=11");
            builder.AppendLine("END:STANDARD");
            builder.AppendLine("BEGIN:DAYLIGHT");
            builder.AppendLine("DTSTART:16010101T020000");
            builder.AppendLine("TZOFFSETFROM:-0800");
            builder.AppendLine("TZOFFSETTO:-0700");
            builder.AppendLine("RRULE:FREQ=YEARLY;INTERVAL=1;BYDAY=2SU;BYMONTH=3");
            builder.AppendLine("END:DAYLIGHT");
            builder.AppendLine("END:VTIMEZONE");
            builder.AppendLine("BEGIN:VEVENT");
            builder.AppendLine("ORGANIZER;CN=" + user.Name + ":MAILTO:" + user.EmailAddress);
            builder.AppendLine("ATTENDEE;ROLE=REQ-PARTICIPANT;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;CN=" + user.EmailAddress + ":MAILTO:" + user.EmailAddress);
            builder.AppendLine("DESCRIPTION;LANGUAGE=en-US:" + todo.Task);
            builder.AppendLine("SUMMARY;LANGUAGE=en-US:" + todo.TitleOrTask);
            builder.AppendLine("DTSTART;TZID=Eastern Standard Time:" + todo.DueDate.Value.ToString("yyyyMMdd"));
            builder.AppendLine("DTEND;TZID=Eastern Standard Time:" + todo.DueDate.Value.ToString("yyyyMMdd"));
            builder.AppendLine("UID:" + Guid.NewGuid().ToString());
            builder.AppendLine("CLASS:PUBLIC");
            builder.AppendLine("PRIORITY:5");
            builder.AppendLine("DTSTAMP:" + todo.DueDate.Value.ToString("yyyyMMdd") + "T023422Z");
            builder.AppendLine("TRANSP:OPAQUE");
            builder.AppendLine("STATUS:CONFIRMED");
            builder.AppendLine("SEQUENCE:0");
            if(todo.PropertyId != null) {
                var property = PropertyService.Get(todo.PropertyId);
                builder.AppendLine("LOCATION;LANGUAGE=en-US:" + property.FullAddress);
            }
            else {
                builder.AppendLine("LOCATION;LANGUAGE=en-US:Unknown");
            }
            builder.AppendLine("X-MICROSOFT-CDO-APPT-SEQUENCE:0");
            builder.AppendLine("X-MICROSOFT-CDO-OWNERAPPTID:2112076272");
            builder.AppendLine("X-MICROSOFT-CDO-BUSYSTATUS:TENTATIVE");
            builder.AppendLine("X-MICROSOFT-CDO-INTENDEDSTATUS:BUSY");
            builder.AppendLine("X-MICROSOFT-CDO-ALLDAYEVENT:FALSE");
            builder.AppendLine("X-MICROSOFT-CDO-IMPORTANCE:1");
            builder.AppendLine("X-MICROSOFT-CDO-INSTTYPE:0");
            builder.AppendLine("X-MICROSOFT-DISALLOW-COUNTER:FALSE");
            builder.AppendLine("BEGIN:VALARM");
            builder.AppendLine("ACTION:DISPLAY");
            builder.AppendLine("DESCRIPTION:REMINDER");
            builder.AppendLine("TRIGGER;RELATED=START:-PT15M");
            builder.AppendLine("END:VALARM");
            builder.AppendLine("END:VEVENT");
            builder.AppendLine("END:VCALENDAR");

            return builder.ToString();
        }

Google:

var text = encodeURIComponent('Housters To-Do Due: ' + self.task());
            var startDate = moment(self.dueDate()).format('YYYYMMDD');
            var endDate = moment(self.dueDate()).add('days', 1).format('YYYYMMDD');
            var details = encodeURIComponent(self.task());
            var location = encodeURIComponent(self.propertyName());
            var googleCalendarUrl = 'http://www.google.com/calendar/event?action=TEMPLATE&text=' + text + '&dates=' + startDate + '/' + endDate + '&details=' + details + '&location=' + location;

Here is what I use in case it helps anyone, I'm using ASP.NET MVC / C# but should give you the gist of what's required to build it yourself.

Outlook & iCal:

var icsUrl = '/todos/geticsfile/' + id;

public ActionResult GetIcsFile(string id) {
            var user = UserService.Get(UserId);
            var todo = ToDoService.Get(id);
            var content = GetOutlookFileContents(user, todo);
            var bytes = Encoding.UTF8.GetBytes(content);
            return File(bytes, "text/calendar", "housters-todo.ics");
        }

public static string GetOutlookFileContents(User user, ToDo todo) {
            var builder = new StringBuilder();

            builder.AppendLine("BEGIN:VCALENDAR");
            builder.AppendLine("METHOD:REQUEST");
            builder.AppendLine("PRODID:Microsoft Exchange Server 2010");
            builder.AppendLine("VERSION:2.0");
            builder.AppendLine("BEGIN:VTIMEZONE");
            builder.AppendLine("TZID:Eastern Standard Time");
            builder.AppendLine("BEGIN:STANDARD");
            builder.AppendLine("DTSTART:16010101T020000");
            builder.AppendLine("TZOFFSETFROM:-0700");
            builder.AppendLine("TZOFFSETTO:-0800");
            builder.AppendLine("RRULE:FREQ=YEARLY;INTERVAL=1;BYDAY=1SU;BYMONTH=11");
            builder.AppendLine("END:STANDARD");
            builder.AppendLine("BEGIN:DAYLIGHT");
            builder.AppendLine("DTSTART:16010101T020000");
            builder.AppendLine("TZOFFSETFROM:-0800");
            builder.AppendLine("TZOFFSETTO:-0700");
            builder.AppendLine("RRULE:FREQ=YEARLY;INTERVAL=1;BYDAY=2SU;BYMONTH=3");
            builder.AppendLine("END:DAYLIGHT");
            builder.AppendLine("END:VTIMEZONE");
            builder.AppendLine("BEGIN:VEVENT");
            builder.AppendLine("ORGANIZER;CN=" + user.Name + ":MAILTO:" + user.EmailAddress);
            builder.AppendLine("ATTENDEE;ROLE=REQ-PARTICIPANT;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;CN=" + user.EmailAddress + ":MAILTO:" + user.EmailAddress);
            builder.AppendLine("DESCRIPTION;LANGUAGE=en-US:" + todo.Task);
            builder.AppendLine("SUMMARY;LANGUAGE=en-US:" + todo.TitleOrTask);
            builder.AppendLine("DTSTART;TZID=Eastern Standard Time:" + todo.DueDate.Value.ToString("yyyyMMdd"));
            builder.AppendLine("DTEND;TZID=Eastern Standard Time:" + todo.DueDate.Value.ToString("yyyyMMdd"));
            builder.AppendLine("UID:" + Guid.NewGuid().ToString());
            builder.AppendLine("CLASS:PUBLIC");
            builder.AppendLine("PRIORITY:5");
            builder.AppendLine("DTSTAMP:" + todo.DueDate.Value.ToString("yyyyMMdd") + "T023422Z");
            builder.AppendLine("TRANSP:OPAQUE");
            builder.AppendLine("STATUS:CONFIRMED");
            builder.AppendLine("SEQUENCE:0");
            if(todo.PropertyId != null) {
                var property = PropertyService.Get(todo.PropertyId);
                builder.AppendLine("LOCATION;LANGUAGE=en-US:" + property.FullAddress);
            }
            else {
                builder.AppendLine("LOCATION;LANGUAGE=en-US:Unknown");
            }
            builder.AppendLine("X-MICROSOFT-CDO-APPT-SEQUENCE:0");
            builder.AppendLine("X-MICROSOFT-CDO-OWNERAPPTID:2112076272");
            builder.AppendLine("X-MICROSOFT-CDO-BUSYSTATUS:TENTATIVE");
            builder.AppendLine("X-MICROSOFT-CDO-INTENDEDSTATUS:BUSY");
            builder.AppendLine("X-MICROSOFT-CDO-ALLDAYEVENT:FALSE");
            builder.AppendLine("X-MICROSOFT-CDO-IMPORTANCE:1");
            builder.AppendLine("X-MICROSOFT-CDO-INSTTYPE:0");
            builder.AppendLine("X-MICROSOFT-DISALLOW-COUNTER:FALSE");
            builder.AppendLine("BEGIN:VALARM");
            builder.AppendLine("ACTION:DISPLAY");
            builder.AppendLine("DESCRIPTION:REMINDER");
            builder.AppendLine("TRIGGER;RELATED=START:-PT15M");
            builder.AppendLine("END:VALARM");
            builder.AppendLine("END:VEVENT");
            builder.AppendLine("END:VCALENDAR");

            return builder.ToString();
        }

Google:

var text = encodeURIComponent('Housters To-Do Due: ' + self.task());
            var startDate = moment(self.dueDate()).format('YYYYMMDD');
            var endDate = moment(self.dueDate()).add('days', 1).format('YYYYMMDD');
            var details = encodeURIComponent(self.task());
            var location = encodeURIComponent(self.propertyName());
            var googleCalendarUrl = 'http://www.google.com/calendar/event?action=TEMPLATE&text=' + text + '&dates=' + startDate + '/' + endDate + '&details=' + details + '&location=' + location;
淤浪 2024-10-27 05:59:39

对于日历事件,您可以使用此库
https://www.npmjs.com/package/add-event-to-日历

for calendar events, you can use this lib
https://www.npmjs.com/package/add-event-to-calendar

所谓喜欢 2024-10-27 05:59:39

我认为这是做到这一点的最佳选择。该插件可以从 html 上的变量创建 .ics 文件。

http://addtocalendar.com/

I thinks this is the best option to do this. This plugin can create a .ics file from variables on html.

http://addtocalendar.com/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文