日历下载 - 使用IE和& S的脚本代码出错了。苹果浏览器

时间:2015-09-08 19:27:31

标签: javascript jquery safari calendar

我对这个脚本有一些问题:

 // Download invitation file: added 08/09/2015
    //only for breezing form jQuery( '[name="ff_nm_InvitationFile[]"]' ).click(function() {
        //alert('button click');
        var dateStamp = new Date();
        //alert('dateStamp='+dateStamp);
        var dtStamp = dateToICS(dateStamp);
        var dateText = $('[name="ff_nm_Appointmentdatebooked[]"]' ).val();
        //alert('dateText='+dateText);
        var dateStart = new Date(dateText.replace(/-/g, '/') + ' 09:00 am');
        //alert('dateStart='+dateStart);
        var dtStart = dateToICS(dateStart);
        var dateEnd = new Date(dateText.replace(/-/g, '/') + ' 06:00 pm');
        var dtEnd= dateToICS(dateEnd);
        var icsMSG = "BEGIN:VCALENDAR\n";
        icsMSG += "VERSION:2.0\n";
        icsMSG += "PRODID:-//xxxxxxx//NONSGML v1.0//EN\n";
        icsMSG += "BEGIN:VEVENT\n";
        icsMSG += "UID:" + dtStamp + "@xxxxxxx\n";
        icsMSG += "DTSTAMP:" + dtStamp + "\n";
        icsMSG += "ATTENDEE;CN=My Self ;RSVP=TRUE:MAILTO:" + $('[name="ff_nm_email[]"]' ).val() + "\n";
        icsMSG += "ORGANIZER;CN=New Smile Prague:MAILTO:newsmilepartners@gmail.com\n";
        icsMSG += "DTSTART:" + dtStart + "\n";
        icsMSG += "DTEND:" + dtEnd + "\n";
        icsMSG += "LOCATION:Prague\n";
        icsMSG += "SUMMARY:my calendar\n";
        icsMSG += "END:VEVENT\n";
        icsMSG += "END:VCALENDAR";
        //window.open( "data:text/calendar;charset=utf8," + escape(icsMSG));
        var fileName = "InvitationFile";
        //alert('dopo icsMSG');
        if (navigator.userAgent.search("MSIE") >= 0) {
            //This peice of code is not working in IE, we will working on this
            //TODO
            var uriContent = "data:application/octet-stream;filename=" + fileName + '.ics' + "," + escape(icsMSG);
            window.open(uriContent + fileName + '.ics');
        } else {
            //alert ('Parto dopo else');
            var uri = 'data:text/calendar;charset=utf-8,' + escape(icsMSG);
            var downloadLink = document.createElement("a");
            downloadLink.href = uri;
            downloadLink.download = fileName + ".ics";
            document.body.appendChild(downloadLink);
            downloadLink.click();
            document.body.removeChild(downloadLink);
        }
    });

它非常适合Firefox& Chrome但是......使用Safari下载文件是未知的,它不适用于IE。此脚本可以生成包含要下载的文件.ics的文件。

为什么这不适用于Safari和IE?

0 个答案:

没有答案