javascript - Internet Explorer 打开 Outlook 约会 javascript

标签 javascript html internet-explorer

想想看,我在使用 IE 时遇到了问题,希望有人能够提供帮助...... 我有一个网站,访问者可以在该网站上报名参加特定的 session ,然后我希望能够为他们选择的日历生成约会;选项包括 Gmail、yahoo 和 Outlook。 gmail 和 yahoo 约会在所有浏览器中均按预期生成,但 Outlook 约会在除 IE 之外的所有浏览器中均有效。 IE 不会抛出文件保存对话框,而是打开一个新窗口并尝试导航该 URL。

我正在使用稍微修改过的 iCalendar jquery 库,并在 JavaScript 中构建 ics 标记,如下所示

//build ics markup
var event = makeAppointment(settings);
//render ics markup as outlook appointment
window.open("data:text/calendar;charset=utf8," + escape(event));

function makeAppointment()
{
    return 'BEGIN:VCALENDAR\n' +
    'VERSION:2.0\n' +
    'PRODID:jquery.icalendar\n' +
    'METHOD:PUBLISH\n' +
    'BEGIN:VEVENT\n' +
    'UID:' + new Date().getTime() + '@' +
    (window.location.href.replace(/^[^\/]*\/\/([^\/]*)\/.*$/, '$1') || 'localhost')       + '\n' +
    'DTSTAMP:' + $.icalendar.formatDateTime(new Date()) + '\n' +
    (event.url ? limit75('URL:' + event.url) + '\n' : '') +
    (event.contact ? limit75('MAILTO:' + event.contact) + '\n' : '') +
    limit75('TITLE:' + event.title) + '\n' +
    'DTSTART:' + $.icalendar.formatDateTime(event.start) + '\n' +
    'DTEND:' + $.icalendar.formatDateTime(event.end) + '\n' +
    (event.summary ? limit75('SUMMARY:' + event.summary) + '\n' : '') +
    (event.description ? limit75('DESCRIPTION:' + event.description) + '\n' : '') +
    (event.location ? limit75('LOCATION:' + event.location) + '\n' : '') +
    (event.recurrence ? makeRecurrence(event.recurrence) + '\n' : '') +
    'END:VEVENT\n' +
    'END:VCALENDAR';
}

最佳答案

您可以通过添加“Content-Disposition:附件”响应 header 来使文件保存对话框在 IE 中工作。但是,这必须发生在服务器上,而不能发生在客户端脚本中,因为 JavaScript 无法修改 header 信息。

参见this answer相关详情。

关于javascript - Internet Explorer 打开 Outlook 约会 javascript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10317556/

相关文章:

javascript - 如何在div onClick中获取元素的文本内容? React.js、JavaScript

html - 什么情况下可以得到 "Application Cache Obsolete event "

html - IE 中的 SVG 垂直对齐问题

jquery - 如果 URL 包含阿拉伯字符,Ajax 在 IE 中不起作用

internet-explorer - 页面无法在 IE7 或 IE8 中完全加载(但可以在其他浏览器中使用)

javascript - 如何过滤具有多个参数的javaScript数组

java - 从 Applet 读取 html 源代码时避免重定向

javascript - Google Apps 脚本基于时间的触发器,根据电子表格中的值在自定义日期和时间触发

javascript - 下拉选择不自动填充文本框

php - HTML DOM : how to properly use the textContent property with PHP