简体   繁体   English

无法在 safari 浏览器中下载 ICS 文件

[英]Not able to Download ICS file in safari browser

I am trying to download ICS file in all the browsers.我正在尝试在所有浏览器中下载 ICS 文件。 I am able to download ICS file in chrome but not in safari.我可以在 chrome 中下载 ICS 文件,但不能在 safari 中下载。 Here is the javascript code that i used.这是我使用的 javascript 代码。

if(isChrome)
{
            var blob=new Blob([data]);
            var link=document.createElement('a');
            link.href=window.URL.createObjectURL(blob);
            link.download=fileName+".ics";
            link.click()
}
if(!isChrome) 
{
`   alert("not chrome");
    var downloadLink = document.createElement('a');
    downloadLink.setAttribute('href', 'data:application/octet;charset=utf-8,' + escape(data));
    var fileName = fileName+'.ics';
    downloadLink.setAttribute('download', fileName);
    var clk = document.createEvent("MouseEvent");
    clk.initEvent("click", true, true);
    downloadLink.dispatchEvent(clk);
    document.body.appendChild(downloadLink);
    downloadLink.dispatchEvent(clk);
    //download(data, fileName+".ics", "text/calendar");
}

In Safari browser the generated file is getting downloaded but that file name is not getting appended.在 Safari 浏览器中,生成的文件正在下载,但该文件名未附加。 The filename i am getting is "Unknown" but the size of the file is 3KB and the content is there only the filename and extension is not getting added to the file.我得到的文件名是“未知”,但文件的大小是 3KB,内容只有文件名和扩展名没有添加到文件中。

Please let me know how i can solve this issue.请让我知道如何解决这个问题。

Thanks in advance提前致谢

If the problem is that you're using safari 10.1 or below the problem might be that it doesn't like the download attr.如果问题是您使用的是 safari 10.1 或更低版本,则问题可能是它不喜欢下载属性。 http://caniuse.com/#feat=download http://caniuse.com/#feat=download

You should specify blob type.您应该指定 blob 类型。 { type: 'text/calendar' } { 类型:'文本/日历' }

 const blob = new Blob([data], { type: 'text/calendar' }); const link = document.createElement('a'); link.href = window.URL.createObjectURL(blob); link.download = filename + ".ics" ; link.click();

Use this to download the file successfully, but you have to manually add it to the calendar.使用它可以成功下载文件,但您必须手动将其添加到日历中。 Safari does not include ics in a list of safe files and it will not be opened automatically. Safari 不会将 ics 包含在安全文件列表中,并且不会自动打开。 在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM