数据:Internet Explorer无法识别的文本/日历 [英] data:text/calendar not recognized by Internet Explorer

查看:212
本文介绍了数据:Internet Explorer无法识别的文本/日历的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试仅使用JavaScript即时创建一个ics文件,而不进行中间保存.我只能使用JavaScript,并且由于最终将在其上运行的平台而无法保存.

I'm trying to create an ics file on the fly using only JavaScript without an intermediate save. I'm restricted to JavaScript and no save because of the platform this will eventually be running on.

我是JavaScript的新手,但是通过网上的大量搜索,我已经拼凑了一些(几乎)可行的方法.我提供的功能在Chrome,Firefox甚至Opera中都可以使用,但是在Internet Explorer中却无法使用.在所有其他浏览器中,我都创建并下载了一个ics文件,但是在资源管理器中,我得到了"The webpage cannot be displayed",并在地址栏中显示了整个ics流,并以以下内容开头:

I'm a novice JavaScript programmer, but I've cobbled together something that works (almost) by a lot of searching on the web. What I've come up with works in Chrome, Firefox, and even Opera, but it doesn't work in Internet Explorer. In all other browsers I get an ics file created and downloaded, but in Explorer I get "The webpage cannot be displayed" with the entire ics stream displayed in the address bar beginning with the following:

data:text/calendar;charset=utf8,BEGIN%3AVCALENDAR

"BEGIN"中的所有内容都是ics文件的一部分.

Everything from "BEGIN" on is part of what should be part of the ics file.

在所有其他浏览器中成功开始下载的代码是:

The bit of code that successfully starts the download in all the other browsers is this:

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

icsMSG是组成实际的ics文件的字符串.

icsMSG is the string that composes the actual ics file.

如前所述,唯一的问题是这在IE中不起作用,因为IE似乎不知道该如何处理"data:text/calendar" ...或者也许我已经完全脱离基础,只是不了解知道我在做什么.

As mentioned the only issue is that this isn't working in IE as IE doesn't seem to know what to do with "data:text/calendar" ... or perhaps I'm completely off base and just don't know what I'm doing.

如有必要,我可以提供所有代码.

I can supply all of the code if necessary.

谢谢!

推荐答案

我在其中icsMSG是一个字符串,其中包含应该在ICS文件中的数据(所有从"BEGIN"开始的内容).您还可以在中使用if语句该项目中的另一个文件,以测试浏览器是否是IE的旧版本:

Where icsMSG is a string containing the data that should be in your ICS file (everything starting from "BEGIN"). There is also an if statement you can use in another file from this project to test if the browser is an older version of IE:

if (typeof window !== "undefined" &&
    window.navigator.msSaveOrOpenBlob &&
    window.Blob) { }

这在Internet Explorer 11中对我有用,而无需使用服务器下载文件.

This is working for me in Internet Explorer 11 without having to use a server to download the file.

这篇关于数据:Internet Explorer无法识别的文本/日历的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆