Javascript:如何通过按钮将事件添加到 Outlook 日历

发布于 2024-11-08 07:20:36 字数 1351 浏览 0 评论 0原文

我目前编写了一个有效的 vbscript 实现:

<code>
<script language="VBScript">
    <!--
    sub MakeAppointment(MySubject, MyLocation, MyStart, MyEnd, MyMessage)
    Dim objOutlook
    Dim itmCalendar
    Set objOutlook = CreateObject("Outlook.application")
    Set itmCalendar = objOutlook.CreateItem(1)

    itmCalendar.Subject = MySubject
    itmCalendar.Location = MyLocation
    itmCalendar.Start = MyStart
    itmCalendar.End = MyEnd
    itmCalendar.Body = MyMessage

    itmCalendar.Save

    Msgbox "Appointment has been added to your Outlook Calendar!", 0, MyStart

    Set itmCalendar = Nothing
    Set objOutlook = Nothing
    end sub
    -->
</script>
<script language="VBScript">
    <!-- 
    Sub btnAdd_onclick()
    MySubject="All your base are belong to us" 
    MyLocation="Japan"
    MyStart="05/19/2011 07:00"
    MyEnd="05/19/2011 08:00"
    MyMessage = "This is a English review course." & vbcrlf
    MyMessage = MyMessage & "" & vbcrlf
    MyMessage = MyMessage & "" & vbcrlf
    MyMessage = MyMessage & "" & vbcrlf
    MakeAppointment MySubject, MyLocation, MyStart, MyEnd, MyMessage
    End Sub
    -->
</script>
</code>

我需要一些帮助来了解如何为 Javascript 重写它,因为我正在编写的另一个 SharePoint 网站正在使用 Javascript 作为其默认验证脚本语言。有可能吗?有任何可能的资源链接来实现这一目标吗?

I currently have a working vbscript implementation written:

<code>
<script language="VBScript">
    <!--
    sub MakeAppointment(MySubject, MyLocation, MyStart, MyEnd, MyMessage)
    Dim objOutlook
    Dim itmCalendar
    Set objOutlook = CreateObject("Outlook.application")
    Set itmCalendar = objOutlook.CreateItem(1)

    itmCalendar.Subject = MySubject
    itmCalendar.Location = MyLocation
    itmCalendar.Start = MyStart
    itmCalendar.End = MyEnd
    itmCalendar.Body = MyMessage

    itmCalendar.Save

    Msgbox "Appointment has been added to your Outlook Calendar!", 0, MyStart

    Set itmCalendar = Nothing
    Set objOutlook = Nothing
    end sub
    -->
</script>
<script language="VBScript">
    <!-- 
    Sub btnAdd_onclick()
    MySubject="All your base are belong to us" 
    MyLocation="Japan"
    MyStart="05/19/2011 07:00"
    MyEnd="05/19/2011 08:00"
    MyMessage = "This is a English review course." & vbcrlf
    MyMessage = MyMessage & "" & vbcrlf
    MyMessage = MyMessage & "" & vbcrlf
    MyMessage = MyMessage & "" & vbcrlf
    MakeAppointment MySubject, MyLocation, MyStart, MyEnd, MyMessage
    End Sub
    -->
</script>
</code>

I am in need of some help on how to re-write this for Javascript as another SharePoint site I am writing for is using Javascript as its default validation script language. Is it even possible? Any links to possible resources on getting this accomplished?

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

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

发布评论

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

评论(4

一杆小烟枪 2024-11-15 07:20:36

接受的答案对我没有帮助。因此,我将发布截至 2015 年 12 月我发现有帮助的内容。

http://calendar.live.com/calendar/calendar.aspx?rru=addevent

参数:

dtstart (yyyymmddThhmmss)

必填。指定事件的开始日期和时间。例如,
20110101T120000 代表2011年1月1日中午。请注意,
指定事件时间 (T120000) 的部分是可选的。

dtend (yyyymmddThhmmss)

必填。指定事件的结束日期和时间。例如,
20110101T120000 代表2011年1月1日中午。请注意,
指定事件时间 (T120000) 的部分是可选的。

摘要转义字符串

可选。指定事件的标题。

位置转义字符串

可选。指定事件的位置文本。

<a href="http://calendar.live.com/calendar/calendar.aspx?rru=addevent&dtstart=2015-12-07T20:00:00+00:00&dtend=2015-12-07T22:00:00+00:00&summary=Weekly Planning&location=BigCoHQ">Add to Outlook</a>

来源:msdn.microsoft.com

The accepted answer didn't help me. So I will post what I found helpful as of December 2015.

http://calendar.live.com/calendar/calendar.aspx?rru=addevent

Parameters:

dtstart (yyyymmddThhmmss)

Required. Specifies the event's start date and time. For example,
20110101T120000 represents January 1, 2011, at noon. Note that the
portion specifying the event time (T120000) is optional.

dtend (yyyymmddThhmmss)

Required. Specifies the event's end date and time. For example,
20110101T120000 represents January 1, 2011, at noon. Note that the
portion specifying the event time (T120000) is optional.

summary (Escaped string)

Optional. Specifies the event's title.

location (Escaped string)

Optional. Specifies the event’s location text.

<a href="http://calendar.live.com/calendar/calendar.aspx?rru=addevent&dtstart=2015-12-07T20:00:00+00:00&dtend=2015-12-07T22:00:00+00:00&summary=Weekly Planning&location=BigCoHQ">Add to Outlook</a>

Source: msdn.microsoft.com

青衫负雪 2024-11-15 07:20:36

我设法通过将事件信息直接填充到 Outlook 链接来解决此问题,因此它会将您重定向到一个模式,您可以在将事件信息保存到日历之前验证该模式是否正确。

<a href="https://outlook.live.com/owa/?path=/calendar/view/Month&rru=addevent&startdt=20200213T000000Z&enddt=20200214T000000Z&subject=Test+Event&location=Dublin">Add to Outlook Calendar</a>

以下链接示例包含您想要从对象填充信息的参数

https://outlook .live.com/owa/?path=/calendar/view/Month&rru=addevent&startdt=${eventStart}&enddt=${eventEnd}&subject=${eventName}&location=${eventLocation }&body=${eventDescription}

I managed to solve this by populating the event information directly to the outlook link, so it'll redirect you to a modal that you can verify if the event information is correct before saving it to your calendar.

<a href="https://outlook.live.com/owa/?path=/calendar/view/Month&rru=addevent&startdt=20200213T000000Z&enddt=20200214T000000Z&subject=Test+Event&location=Dublin">Add to Outlook Calendar</a>

The following link example contains the parameters in case you want to populate information from an object

https://outlook.live.com/owa/?path=/calendar/view/Month&rru=addevent&startdt=${eventStart}&enddt=${eventEnd}&subject=${eventName}&location=${eventLocation}&body=${eventDescription}

白况 2024-11-15 07:20:36

接受的答案对我不起作用。这是截至 2022 年 11 月有效的版本:

https://outlook.live.com/calendar/0/deeplink/compose?allday=false&body=This%20is%20event%20description&enddt=2022-11-29T15%3A15%3A00%2B00%3A00&path=%2Fcalendar%2Faction%2Fcompose&rru=addevent&startdt=2022-11-29T14%3A45%3A00%2B00%3A00&subject=TestEvent

您也可以通过此链接生成它:https:// /www.labnol.org/calendar/

The accepted answer didn't work for me. Here is the one which is working as of November 2022:

https://outlook.live.com/calendar/0/deeplink/compose?allday=false&body=This%20is%20event%20description&enddt=2022-11-29T15%3A15%3A00%2B00%3A00&path=%2Fcalendar%2Faction%2Fcompose&rru=addevent&startdt=2022-11-29T14%3A45%3A00%2B00%3A00&subject=TestEvent

You can generate it via this link as well: https://www.labnol.org/calendar/

明明#如月 2024-11-15 07:20:36

为了获得更具可读性和可用性的代码,我分隔了日历的字段。日期需要像 '2023-08-07T01:00:00.000Z' 这样的 ISO 格式,其他所有内容都只是一个字符串。

如果您只想要最终的href,可以使用另一个答案 https://www.labnol.org/calendar/,这将生成您可以使用的最终网址。

const event = {
  title: "Event title",
  description: "This is the description",
  startTime: new Date("Aug 06 2023 19:00:00"),
  endTime: new Date("Aug 06 2023 22:00:00"),
  address: "123 main street",
}

let href = encodeURI(
  [
    "https://outlook.live.com/calendar/0/action/compose",
    "?allday=false",
    "&body=" + event.description,
    "&enddt=" + event.endTime.toISOString(),
    "&location=" + event.address,
    "&path=%2Fcalendar%2Faction%2Fcompose",
    "&rru=addevent",
    "&startdt=" + event.startTime.toISOString(),
    "&subject=" + event.title,
  ].join("")
);

之后,您只需在锚标记或您想要使用的任何元素中设置 href,例如 document.querySelector("#outlook-link").href = href"

In order to have a more readable and usable code I separated the fields for the calendar. The date needs an ISO format like '2023-08-07T01:00:00.000Z', and everything else is just a string.

If you only want the final href, you can use the link provided in another answer https://www.labnol.org/calendar/, which will generate the final url you can use.

const event = {
  title: "Event title",
  description: "This is the description",
  startTime: new Date("Aug 06 2023 19:00:00"),
  endTime: new Date("Aug 06 2023 22:00:00"),
  address: "123 main street",
}

let href = encodeURI(
  [
    "https://outlook.live.com/calendar/0/action/compose",
    "?allday=false",
    "&body=" + event.description,
    "&enddt=" + event.endTime.toISOString(),
    "&location=" + event.address,
    "&path=%2Fcalendar%2Faction%2Fcompose",
    "&rru=addevent",
    "&startdt=" + event.startTime.toISOString(),
    "&subject=" + event.title,
  ].join("")
);

After this you can just set the href in your anchor tag or whatever element you want to use like document.querySelector("#outlook-link").href = href"

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