문제

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?

도움이 되었습니까?

해결책

To get around this problem i generated the iCal file one the server side and exposed to the Client via a RESTful webservice.

In order to identify the response as of type calendar i set the following

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

When IE8 receives the response it automatically attempts to download/open the file using my default Outlook instance.

This works across all browsers. It does have the overhead of requiring the request to the server however it also lets me apply extra processing on the request like validating the conference room is valid etc.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top