0

I'm trying to dynamically generate a vCal file using Javascript and everything is working fine until i try in IE8. In IE8 the browser tries to open the calendar file in the request bar instead of downloading. This is a sample of the code i use

var iCal = 
    "BEGIN:VCALENDAR\n" +
    "PRODID:-//Microsoft Corporation//Outlook 14.0 MIMEDIR//EN\n" +
    "METHOD:PUBLISH\n" +
    "BEGIN:VEVENT\n" +
    "ATTENDEE;CN=\""+locationAlias+"\";CUTYPE=RESOURCE;ROLE=NON-PARTICIPANT;RSVP=TRUE:mailto:"+locationEmail+"\n" +
    "DTEND;TZID=\"GMT Standard Time\":"+dend+"\n" +
    "DTSTART;TZID=\"GMT Standard Time\":"+dstart+"\n" +
    "LOCATION:"+locationName+"\n" +
    "ORGANIZER;CN=\"<someuser>\":mailto:<somemailto>\n" +
    "END:VEVENT\n" +
    "END:VCALENDAR";

return iCal;

I then try to open the calendar file using the following;

window.open( "data:text/calendar;charset=utf8," + escape( iCal) );

Any suggestions as to why IE8 cannot recognize the file?

4

1 回答 1

-1

为了解决这个问题,我在服务器端生成了 iCal 文件,并通过 RESTful Web 服务向客户端公开。

为了识别日历类型的响应,我设置了以下内容

ResponseBuilder builder = Response.ok();
    builder.header("content-disposition",
            "attachment;filename=calendar.ics");

当 IE8 收到响应时,它会自动尝试使用我的默认 Outlook 实例下载/打开文件。

这适用于所有浏览器。它确实有要求向服务器发出请求的开销,但它也让我可以对请求进行额外处理,例如验证会议室是否有效等。

于 2013-07-08T10:14:24.317 回答